SQL Flashcards
What is PostgreSQL and what are some alternative relational databases?
a free open source Relational Database Management System, MySQL, SQL Server (Microsoft), Oracle (Oracle Corporation)
What are some advantages of learning a relational database?
they are the most widely used kind of database
What is one way to see if PostgreSQL is running?
sudo service postgresql status or top
What is a database schema?
a description of how data should be structured
What is a table?
a list of rows having the same set of attributes
What is a row?
all of the data for an individual entry
What is SQL and how is it different from languages like JavaScript?
Structured Query Language, the primary way of interacting with relational databases, declarative programming language (like HTML and CSS)
How do you retrieve specific columns from a database table?
select “column”, from “table”
How do you filter rows based on some specific criteria?
where “column” = ‘value’
What are the benefits of formatting your SQL?
readability, style 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 #
How do you retrieve all columns from a database table?
select *
How do you control the sort order of a result set?
order by “column” (desc)
How do you add a row to a SQL table?
insert into “table” (“column”)
values (‘value’)
What is a tuple?
a list of values
How do you add multiple rows to a SQL table at once?
specify 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 “table”
set “column” = ‘value’
where “column” = ‘value’
Why is it important to include a where clause in your update statements?
if where clause isn’t used, all rows would be updated
How do you delete rows from a database table?
delete from “table”
where “column” = ‘value’
How do you accidentally delete all rows from a table?
by not including a where clause
What is a foreign key?
a column that links tables together
How do you join two SQL tables?
join “table” using (“column”)
How do you temporarily rename columns or tables in a SQL statement?
create an alias by using as keyword
select “column” as “alias”
What are some examples of aggregate functions?
max( ), count( ), min( ), sum( )
What is the purpose of a group by clause?
to separate rows into groups and perform aggregate functions on those groups