SQL / PostgreSQL Flashcards
What is SQL and how is it different from languages like JavaScript?
SQL is a querying language, unlike JavaScript it’s declarative, the user declares the desired end-result and doesn’t actually program how it’s achieved.
How do you retrieve specific columns from a database table?
select “columnNameOne”, “columnNameTwo” from “table”
How do you filter rows based on some specific criteria?
where “attribute” = ‘value’
What are the benefits of formatting your SQL?
Easier readability for others and your future self.
What are four comparison operators that can be used in a where clause?
=, !=, greater than, less than
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 * from “table”
How do you control the sort order of a result set?
order by “attributeName”
How do you add a row to a SQL table?
insert into “table” (“attrOne”, “attrTwo”, … “attrN”)
values (‘valOne’, ‘valTwo’, … ‘valN’)
What is a tuple?
A row of data in a table.
How do you add multiple rows to a SQL table at once?
Add more tuples after values and separate them with commas.
How do you get back the row being inserted into a table without a separate select statement?
returning *
How do you update rows in a database table?
update “table”
set (“colOne” = ‘valOne’, “colTwo” = ‘valTwo’, … “colN” = ‘valN’)
where condition;
Why is it important to include a where clause in your update statements?
So updates are only applied to the desired rows.
How do you delete rows from a database table?
delete from “table”
where condition;