PostgreSQL Flashcards
What is PostgreSQL and what are some alternative relational databases?
PostgreSQL is a powerful, free, open source Relational Database Management System (RDBMS).
Other popular relational databases include MySQL (also free), SQL Server by Microsoft, and Oracle by Oracle Corporation.
What are some advantages of learning a relational database?
they can be modeled well, data corruption is very unlikely, and they are widely used
What is one way to see if PostgreSQL is running?
sudo service postgresql status
What is a database schema?
A collection of tables is called a schema. It defines how data 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?
collection of data for a single item
What is SQL and how is it different from languages like JavaScript?
SQL is different! SQL 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.
JavaScript is imperative
How do you retrieve specific columns from a database table?
select “name”
How do you filter rows based on some specific criteria?
where “category” = ‘cleaning’;
What are the benefits of formatting your SQL?
makes it easier to read
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 1;
at end of code
How do you retrieve all columns from a database table?
Select*
How do you control the sort order of a result set?
order by price
DESC if you want descending instead of ascending
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?
In SQL, a list of values is referred to as a tuple.
How do you add multiple rows to a SQL table at once?
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?
If you only want specific values back, you can use a comma-separated list of column names instead of an * asterisk for the returning statement
How do you update rows in a database table?
update “products”
set “price” = 100
where “productId” = 24;
Why is it important to include a where clause in your update statements?
so it doesn’t update everything 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 “products”;
What is a foreign key?
The column that links two tables together since it is in both tables
How do you join two SQL tables?
select “products”.”name” as “product”,
“suppliers”.”name” as “supplier”
from “products”
join “suppliers” using (“supplierId”);