Databases Flashcards
What is PostgreSQL and what are some alternative relational databases?
open-source relational database system; some others are MySQL, SQL Server, and Oracle
What are some advantages of learning a relational database?
good for modeling and storing related data; also supports good guarantees about data integrity
What is one way to see if PostgreSQL is running?
sudo service postgresql status
What is a database schema?
a collection of tables in a relational database that defines how the data should be organized
What is a table?
a list of rows each having the same set of attributes
What is a row?
a record in the database
What is SQL and how is it different from languages like JavaScript?
SQL is a declarative programming language, while JavaScript is an imperative programming language
How do you retrieve specific columns from a database table?
select clause indicating column names
How do you filter rows based on some specific criteria?
where clause
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 clause
How do you retrieve all columns from a database table?
select *
How do you control the sort order of a result set?
order by
How do you add a row to a SQL table?
insert into “tableName” (“columnNames”)
values (‘values’)
What is a tuple?
a list of values
How do you add multiple rows to a SQL table at once?
insert into … values… - specify each tuple of values in parentheses, separated by commas
How do you get back the row being inserted into a table without a separate select statement?
returning * (or columnNames) - add to the end of the insert into statement
How do you update rows in a database table?
update “tableName”, set “columnName” = value
Why is it important to include a where clause in your update statements?
to target the specific rows you want to update
How do you delete rows from a database table?
delete from “tableName” where “columnName” = ‘value’
How do you accidentally delete all rows from a table?
if you don’t include the where clause to specify the rows you want to delete
What is a foreign key?
a column in one table that references a value in another table
How do you join two SQL tables?
join “otherTable” using (“foreignKey”)
How do you temporarily rename columns or tables in a SQL statement?
use as to specify the alias
What are some examples of aggregate functions?
sum( ), avg( ), max( ), min( ), count( ), every( )
What is the purpose of a group by clause?
allows you to separate rows into groups and perform aggregate functions on those groups of rows