PostgreSQL Flashcards
What is PostgreSQL and what are some alternative relational databases?
o Open source Relational Database Management System (RDBMS)
o Alternative RDBMS include:
Proprietary (pay money to use) - Oracle
Open Source (like postgres) - MySQL
What are some advantages of learning a relational database?
o Widely used
o They support good guarantees about data integrity
o Store and modify data in a way that makes data corruption unlikely
o Many relational databases are driven by almost the same language
What is one way to see if PostgreSQL is running?
o sudo service postgresql status
o top
What is a database schema?
o Rules for how a data gets stored
o Collection of tables & their structure
What is a table?
o Data stored in relations
o A list of rows that have the same set of attributes
What is a row?
o A distinct record in a table
o A list of attributes and every row in the table has the same attributes
What is SQL and how is it different from languages like JavaScript?
o Structured Query Language (SQL) – primary way of interacting with relational databases (by retrieving, creating and manipulating data).
o SQL is a declarative programming language (unlike JS which is imperative)
How do you retrieve specific columns from a database table?
select “attributeName”
from “tableName”
How do you filter rows based on some specific criteria?
where “attributeName” = ‘value’
What are the benefits of formatting your SQL?
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 set?
limit
How do you retrieve all columns from a database table?
select *
How do you control the sort order of a result set?
order by
How do you add a row to a SQL table?
insert into “tableName” (“attributeName”, . . .)
values (‘value’, ‘value’, . . . );
What is a tuple?
A list of values (one line of values is “one tuple”)
How do you add multiple rows to a SQL table at once?
values (‘value’, ‘value’, . . . ),
values (‘value’, ‘value’, . . . )
(You add multiple tuples separated by a comma)
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 “tableName”
set “attributeName” = ‘newValue’;
Why is it important to include a where clause in your update statements?
To target specific rows
How do you delete rows from a database table?
delete from “tableName”
where “attributeName” = ‘value’
How do you accidentally delete all rows from a table?
If you only write ‘delete from “tableName”’ WITHOUT A WHERE CLAUSE
What is a foreign key?
A column present in one or more tables that links those tables together
How do you join two SQL tables?
join “tableName” using (“foreignkey”)
How do you temporarily rename columns or tables in a SQL statement?
“columnOrTableName” as “newName”
What are some examples of aggregate functions?
o max() o avg() o count() o min() o sum() o every()
What is the purpose of a group by clause?
To separate rows into groups based on a criteria