PostgreSQL Flashcards
What is PostgreSQL and what are some alternative relational databases?
relational database management system that often use some variation of a SQL language (Structured Query Language)
Alternatives: SQLite, mySQL, SQL server, oracle
What are some advantages of learning a relational database?
It’s widely used,
Support good guarantees about data integrity
Uses SQL language (widely used)
What is one way to see if PostgreSQL is running?
sudo service postgresql status
top
What is a database schema?
A collection of tables
Defines how the data in a relational database should be organized
What is a table?
list of rows each having the same set of attributes (columns)
What is a row?
Refers to a data in a table that has the same set of attributes/columns as the other rows
What is SQL and how is it different from languages like JavaScript?
It is a declarative language (declare things and program makes it happen from its predetermined rules
Languages like JS are imperative
How do you retrieve specific columns from a database table?
select “columnName”,
“columnName2”, etc
How do you filter rows based on some specific criteria?
Using the ‘where’ clause
e.g.
where “column” != ‘value’
What are the benefits of formatting your SQL?
It helps with readability
What are four comparison operators that can be used in a where clause?
=, !=,
How do you limit the number of rows returned in a result?
‘limit’ keyword
e.g.
limit 10;
How do you retrieve all columns from a database table?
select *
How do you control the sort order of a result set?
order by “column”
default order is ascending
How do you add a row to a SQL table?
insert into “table” (…columns)
value (…values)
What is a tuple?
A list of values
How do you add multiple rows to a SQL table at once?
have multiple tuples of values
How do you get back the row being inserted into a table without a separate select statement?
returning *;
How do you update rows in a database table?
update “table”
set “column” = ‘value’
where condition(s)
*where clause is important!
Why is it important to include a where clause in your update statement?
If there is no where clause, it will update the entire table
How do you delete rows from a database table?
delete from "table" where condition(s)
How do you accidentally delete all rows from a table?
Using delete from without having a where clause
What is a foreign key?
A shared column/attribute between tables that links/relates one set of data in a table to another
How do you join two SQL tables?
join “table” using (“column”)
How do you temporarily rename columns or tables in a SQL statement?
using as
join “table” using (“column”) as “newName”
select “column” as “newName”
What are some examples of aggregate functions?
max( )
sum( )
count( )
avg( )
What is the purpose of a group by clause?
Collapse/group data into a single row