What is PostgreSQL and what are some alternative relational databases?
PostgreSQL is a powerful, free, open source Relational Database Management System (RDBMS).
Alternative relational databases: MySQL, SQL Server by Microsoft, Oracle by Oracle Corporation, SQLite
What are some advantages of learning a relational database?
What is one way to see if PostgreSQL is running?
On terminal –
top command or
sudo service postgresql status
What is a database schema?
- a schema defines how the data in a relational database should be organized.
What is a table?
- A table is a list of rows each having the same set of attributes
What is a row?
a row is a collection of fields that make up a record / values in a table
What is SQL and how is it different from languages like JavaScript?
Structured Query Language (SQL) is the primary way of interacting with relational databases. It is a powerful way of retrieving, creating, and manipulating data in a relational database.
SQL is different from language like JS because it is a declarative programming language. In declarative languages, programmers describe the results they want and the programming environment comes up with its own plan for getting those results.
How do you retrieve specific columns from a database table?
you use the select statement and double quotes the column’s name. If you want multiple column, use a comma.
How do you filter rows based on some specific criteria?
where clause with the comparison operators
What are the benefits of formatting your SQL?
readability
What are four comparison operators that can be used in a where clause?
less than, greater than, equal to (=), not equal to ( != )
How do you limit the number of rows returned in a result set?
at the end of the code block and input “limit” followed by the number
How do you retrieve all columns from a database table?
select all of the columns in a table by replacing the list of column names with an * asterisk
ex select *
How do you control the sort order of a result set?
use the order by clause followed by the “name” of column and the keyword (desc for descending; ascending order is default).
Select statement notes:
Example: select “name”, “price” from “products”;
Sorting notes:
Example: select *
from “products”
order by “price”;
Filtering notes:
Example: select "productId",
"name",
"price"
from "products"
where "category" = 'cleaning';How do you add a row to a SQL table?
Insert statement
Example - “product” 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 (wrapped in parenthesis)
How do you add multiple rows to a SQL table at once?
Using multiple tuples separated by commas.
Example - “product” table:
insert into “products” (“name”, “description”)
values (‘Ostrich Pillow’, ‘Feel comfy and cozy!’),
(‘Tater Mitts’, ‘Scrub some taters!’)
returning *;
How do you get back the row being inserted into a table without a separate select statement?
returning clause
returning * or the returning attributes
Insert notes:
How do you update rows in a database table?
Update statement
Example - “product” table:
update “products”
set “price” = 100
where “productId” = 24;
Why is it important to include a where clause in your update statements?
So that it don’t update all the rows of the column. The where clause will target specific rows