SQL Flashcards
What is SQL and how is it different from languages like JavaScript?
SQL is declarative - programmer describes results they want and the computer figures it out
JavaScript is imperative - programmer writes the machine instructions
How do you retrieve specific columns from a database table?
Select “column”,
“column”
From “row”;
How do you filter rows based on some specific criteria?
where “column“ = ‘text value’
What are the benefits of formatting your SQL?
To lessen complexity
What are four comparison operators that can be used in a where clause?
Less than, greater than, equal, not equal
How do you limit the number of rows returned in a result set?
limit #
How do you retrieve all columns from a database table?
universal *
How do you control the sort order of a result set?
Order by “column” (desc) or (asc)
How do you add a row to a SQL table?
insert into “table” (“column”, “column”)
values (‘value’, value’);
What is a tuple?
a list of values in SQL
How do you add multiple rows to a SQL table at once?
comma separated list of tuples.
How do you get back the row being inserted into a table without a separate select statement?
returning * or comma-separated column names;
How do you update rows in a database table?
update “table”
set “column” = value
where “target” = target value;
Why is it important to include a where clause in your update statements?
to target a specific row, others all rows would be updated.
How do you delete rows from a database table?
delete
from “table”
where “target” = “target value”
How do you accidentally delete all rows from a table?
by leaving out the “where” clause.
What is a foreign key?
a value in one table that’s the same as value of another table to link them.
How do you join two SQL tables?
from “table” join “table” using (“foreign key”)
How do you temporarily rename columns or tables in a SQL statement?
select “table”.”column” as “alias”
What are some examples of aggregate functions?
max(), avg (), count(), min(), sum(), every()
What is the purpose of a group by clause?
to separate rows into groups and perform aggregate functions on just those groups of rows, rather than every row in table.