What is PostgreSQL and what are some alternative relational databases?
- MySQL, Oracle, SQL Server by Microsoft
What are some advantages of learning a relational database?
Widely adapted database, so can be a highly transferrable language
What is one way to see if PostgreSQL is running?
sudo service postgresql status
What is a database schema?
What is a table?
A table is a list of rows, each having the same set of attributes
What is a row?
- All the data that describes one item inside a table
What is SQL and how is it different from languages like JavaScript?
SQL is a declarative language, so we declare or query for data, and the SQL language finds a path to get us the results
JavaScript is imperative, we write functions by hand, so we tell JS how do handle the action as well.
How do you retrieve specific columns from a database table?
select “column”
If multiple columns, add comma then next column name.
How do you filter rows based on some specific criteria?
Using the where keyword with comparison operator between “column” and data (string, number, boolean)
where “column” = data
What are the benefits of formatting your SQL?
Data is easier to read and comprehend when organized
What are four comparison operators that can be used in awhereclause?
Comparison operators: =, !=, >,
How do you limit the number of rows returned in a result set?
- 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” desc
How do you add a row to a SQL table?
Using insert into keyword followed by the “table”, and the column names in double quotes and parenthesis, separated by commas.
insert into actors (firstName, lastName)
values (‘Ken’ ,’Kieu’)
What is a tuple?
A list of values in SQL
How do you add multiple rows to a SQL table at once?
insert into programming (languages)
values (‘HTML’),
(‘CSS’),
(‘JavaScript’);
How do you get back the row being inserted into a table without a separateselectstatement?
returning *;
or returning specific “column”
How do you update rows in a database table?
update store
set price = 100
where item = ‘electronics’;
Why is it important to include awhereclause in yourupdatestatements?
If where is omitted, it will update all instances of that category
How do you delete rows from a database table?
delete from store
where item = ‘electronics’
How do you accidentally delete all rows from a table?
If where is omitted, it will delete everything
What is a foreign key?
Shared attribute that links two tables together
How do you join two SQL tables?
SELECTorders.orderID, customers.customerName
FROMOrders
JOINcustomersONorders.customerID=customers.customerID;