What is PostgreSQL and what are some alternative relational databases?
What are some advantages of learning a relational database?
What is one way to see if PostgreSQL is running?
sudo service postgresql status
What is a database schema?
-a collection of tables that defines how the data in a relational database should be organized
What is a table in a database?
What are rows and columns in a database?
What is SQL and how is it different from languages like JavaScript?
-where JavaScript is imperative in that you tell JavaScript what to do, SQL is declarative. you just describe the results you want, and SQL will come up with its own plan for getting those results (like html/css)
How do you retrieve specific columns from a database table?
-“select” clause
select “column-name-1”,
“column-name-2”
from “database-table-name”
How do you filter rows based on some specific criteria?
-“where” clause
select “xyz-column”
from “xyz-table-name”
where “xyz-column-2” = “abc”
What are four comparison operators that can be used in a where clause?
, =, and !=
How do you limit the number of rows returned in a result set?
-“limit” clause (comes last)
select *
from “xyz-table-name”
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” clause; asc/desc
How do you add a row to a SQL table?
insert into “products” (“name”, “description”, “price”, “category”)
values (‘Ostrich Pillow’, ‘Feel comfy and cozy!’, 99, ‘self care’);
What is a tuple?
a list of values (aka a row in a database table)
How do you add multiple rows to a SQL table at once?
specify more than one tuple of values, separated by commas
insert into “products” (“name”, “description”, “price”, “category”)
values (‘Ostrich Pillow’, ‘Feel comfy and cozy!’, 99, ‘self care’),
(‘Tater Mitts’, ‘Scrub some taters!’, 6, ‘cooking’)
returning *;
How do you get back the row being inserted into a table without a separate select statement?
“returning” clause
How do you update rows in a database table?
update “products”
set “price” = 200,
“name” = ‘Super ShakeWeight’,
“description” = ‘Makes you ULTRA strong!’
where “productId” = 24;
Why is it important to include a where clause in your update statements?
-if you don’t include a criteria, then the query will update every row in the table
How do you delete rows from a database table?
delete from “products”
where “productId” = 24
returning *;
How do you accidentally delete all rows from a table?
delete from “table-name”;
no “where” clause
What is a foreign key?
a column that specifically refers to values in a column from another table
How do you join two SQL tables?
-“join” clause
select “products”.”name” as “product”,
“suppliers”.”name” as “supplier”
from “products”
join “suppliers” using (“supplierId”);
How do you temporarily rename columns or tables in a SQL statement?
-use keyword “as”
select “products”.”name” as “product”,
“table2”.”columnName” as “supplier”