SQL Flashcards
What is SQL and how is it different from languages like JavaScript?
A declarative programming language. Programmers describe the desired results, and the programming environment finds a way to get that done. In JavaScript, the programmer tells the runtime how to get the results.
How do you retrieve specific columns from a database table?
select “column” from “database table”
How do you filter rows based on some specific criteria?
Using the “where” keyword and some kind of condition (<, >, =, !=)
What are the benefits of formatting your SQL?
Consistency 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” keyword followed by a number will return only the specified number of rows
How do you retrieve all columns from a database table?
select * from “database table”
How do you control the sort order of a result set?
default sort order is ascending order. Including “desc” on the order by line at the end changes the order to descending order
How do you add a row to a SQL table?
insert into “table name” (“column-a”, “column-b”, “column-c”, “column-d”)
values (‘value-a’, ‘value-b’, ‘value-c’, ‘value-d’);
returning *
What is a tuple?
a list of values
How do you add multiple rows to a SQL table at once?
after the values keyword, use comma-separated tuples of values to insert more than one row
How do you get back the row being inserted into a table without a separate select statement?
add a line at the end of the request
returning “columnName”
(* can also be used to return all)
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?
To make sure that the intended row is being updated, otherwise all rows will get updated to the given value
How do you delete rows from a database table?
delete from “table”
where “column” = ‘value’
and “column” (<, >, !=) ‘value’
returning *;