Postgres Flashcards
What is PostgreSQL and what are some alternative relational databases?
a powerful, free, open source Relational Database Management System (RDBMS) MySQL, SQL Server, Oracle
What are some advantages of learning a relational database?
they support good guarantees about data integrity, store and modify data in a way that makes data corruption as unlikely as possible
What is one way to see if PostgreSQL is running?
sudo service postgresql status, or top
What is a database schema?
collection of tables
Defines how the data in a relational database should be organized
What is a table?
relations - where relational databases are store data in a set of rows
What is a row?
Having the same set of attributes
What is SQL and how is it different from languages like JavaScript?
Structured Query Language (SQL) - primary way of interacting with relational databases - a declarative programming language
How do you retrieve specific columns from a database table?
Querying a database typically takes the form of a select statement.
select “name”,
“price”
from “products”;
How do you filter rows based on some specific criteria?
where “category” = ‘cleaning’;
What are the benefits of formatting your SQL?
Consistent style and readability
What are four comparison operators that can be used in a where clause?
=, < >, !=
How do you limit the number of rows returned in a result set?
limit #
How do you retrieve all columns from a database table?
Select *
How do you control the sort order of a result set?
order by “columnName” asc/desc
How do you add a row to a SQL table?
insert statement is a means of adding rows to a table.
What is a tuple?
list of values
How do you add multiple rows to a SQL table at once?
batch inserted into a database table by specifying more than one tuple of values, separated by commas
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 statement followed by set clause
Why is it important to include a where clause in your update statements?
Only need to update a specific item in the table
If no where clause it would update every row in the table
How do you delete rows from a database table?
Using a delete statement followed by table name
How do you accidentally delete all rows from a table?
Delete from “tableName” with nothing else
Need to specify with a where clause
What is a foreign key?
the one specific column that links one table to another table.
How do you join two SQL tables?
Using the join clause
How do you temporarily rename columns or tables in a SQL statement?
Using alias column names
What are some examples of aggregate functions?
max(), avg(), sum(), count()
What is the purpose of a group by clause?
separate/cluster rows into groups and perform aggregate functions on those groups of rows