PostgreSQL Flashcards
What is PostgreSQL and what are some alternative relational databases?
PostgreSQL is a relational database system that is free and open source. Some alternatives are MySQL, SQL Server, and Oracle.
What are some advantages of learning a relational database?
The most widely used kind of database. SQL is a very useful skill to have. Data corruption is very unlikely to happen in a relational database.
What is one way to see if PostgreSQL is running?
By having a 2nd terminal open and running the top command to monitor the open processes.
What is a database schema?
A schema defines how the data in a relational database is organized.
What is a table?
A table is a list of rows each having the same set of attributes(columns).
What is a row?
A row is each individual record or entry that has a set of attributes/columns.
What is SQL and how is it different from languages like JavaScript?
SQLis considered a declarative language. Meaning programmers can declare their intent and the output is the desired result.
How do you retrieve specific columns from a database table?
select “name of column”
How do you filter rows based on some specific criteria?
where “column” (operator) ‘criteria’
What are the benefits of formatting your SQL?
Readability. For the business side of things to interpret the data. Consistency.
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 (number)
How do you retrieve all columns from a database table?
select asterisk*
How do you control the sort order of a result set?
using order by “column”
How do you add a row to a SQL table?
insert into clause followed by the “table” then (column names separated by commas)
What is a tuple?
A list of values. The values being wrapped in parenthesis that are in the same order as the columns they belong to.
How do you add multiple rows to a SQL table at once?
By using multiple tuples which are separated by commas but still follow the same order as the columns they belong to.
How do you get back the row being inserted into a table without a separate select statement?
using the returning keyword along with the star/asterisk
How do you update rows in a database table?
update clause followed by name of table. then the set clause followed by the column that needs updating followed by an equal operator then the value of the desired update
Why is it important to include a where clause in your update statements?
If a where clause is not used, the whole entire table is updated instead of just the targeted/desired data.
How do you delete rows from a database table?
delete from clause followed by the table
How do you accidentally delete all rows from a table?
if a where clause is not used, the entire table will be deleted.
What is a foreign key?
a foreign key is a column that is originally defined/unique in a table and then used in another table as a reference to relate to each table.
How do you join two SQL tables?
from clause followed by the table name and then the join clause followed by the table name as well and then the using keyword to specify the foreign key.
How do you temporarily rename columns or tables in a SQL statement?
when selecting columns, the as keyword is used after the name of the columns stated.
What are some examples of aggregate functions?
max/min, avg, count, sum
What is the purpose of a group by clause?
It allows the grouping of rows so the aggregate functions can be focused on only them. Instead of focusing on every row in the table.