What is PostgreSQL and what are some alternative relational databases?
- SQLite, MySQL, SQL Server, Oracle, Snowflake
What are some advantages of learning a relational database?
What is one way to see if PostgreSQL is running?
top command in the terminal to see if there are any PostgreSQL processes runningsudo service postgresql statusHow do you start and stop a PostgreSQL server from the CLI?
Start: sudo service postgresql start
See UI: pgweb and then visit localhost address
Stop: sudo service postgresql stop
What is ACID?
Atomicity - Transactions are singular units, and these units get accepted or rejected entirely (not halfway)
Consistency - There are rules in place (e.g. table schema enforcement) that prevent invalid data from being written (data could be incorrect, but not invalid)
Isolation - Processes may be run in parallel, but they must affect the database as if they were done sequentially
Durability - Once a transaction has been committed, it stays committed (saved the non-volatile memory)
What is a database schema?
A collection of databases, it determines how data will be organized
What is a table?
A table is made up of rows of data that all have the same attributes represented as columns
What is a row?
A row is made up of data elements, one for each attribute
What is SQL and how is it different from languages like JavaScript?
Structured Query Language, for accessing databases
SQL is a declarative language as opposed to an imperative language like JavaScript, meaning developers code the intent rather than the operations
How do you retrieve specific columns from a database table?
SELECT "col1", "col2"
How do you filter rows based on some specific criteria?
... WHERE criteria
Called a “predicate”
What are the benefits of formatting your SQL?
Readability
What are four comparison operators that can be used in awhereclause?
=, >, <, !=, and the “__ than or equal to” variations
How do you limit the number of rows returned in a result set?
... LIMIT n at the end of the query
How do you retrieve all columns from a database table?
SELECT *
How do you control the sort order of a result set?
ORDER BY "col1" ASC/DESC or you can use the numbers to refer to which column as well
How do you add a row to a SQL table?
Use the INSERT clause
INSERT INTO "table" ("col1", "col2", ...) VALUES ('col1Value', 23);
What is a tuple?
How do you add multiple rows to a SQL table at once?
Use multiple tuples in the VALUES clause, separated by commas
How do you get back the row being inserted into a table without a separateselectstatement?
At the end of the INSERT statement, include the RETURNING clause followed by the columns you want returned
How do you update rows in a database table?
Use the UPDATE clause WITH A WHERE CLAUSE!
UPDATE "table" SET "column" = 'new value' WHERE "id" = 123 RETURNING *;
Why is it important to include awhereclause in yourupdatestatements?
If you don’t, all values in the specified columns in the table will be set to a single value
How do you delete rows from a database table?
Use the DELETE clause WITH A WHERE CLAUSE!
DELETE FROM "table" WHERE "id" = 123 RETURNING *;
How do you accidentally delete all rows from a table?
If you leave off a WHERE clause, the delete operation will happen for every row in the table