SQL Flashcards
What is SQL and how is it different from languages like JavaScript?
SQL is a declarative programming language. In declarative languages, programmers describe the results they want and the programming environment comes up with its own plan for getting those results.
How do you retrieve specific columns from a database table?
select “columns” from table
How do you filter rows based on some specific criteria?
select “columns” from table where “rows”=’content’
What are the benefits of formatting your SQL?
easily readable
What are four comparison operators that can be used in a where clause?
=, < , >, !=
<>(not equal in postgresql)
How do you limit the number of rows returned in a result set?
limit clause and specify the number of rows
How do you retrieve all columns from a database table?
select * from table
How do you control the sort order of a result set?
select * from table order by “” desc
How do you add a row to a SQL table?
insert into table (columns)
values (values)
returning *;
What is a tuple?
a tuple is a finite ordered list of elements. (list of values)
How do you add multiple rows to a SQL table at once?
Data rows can be batch inserted into a database table by specifying 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 *;
How do you update rows in a database table?
update “table”
set “column”
Why is it important to include a where clause in your update statements?
to only target specific rows in the table
How do you delete rows from a database table?
delete from “table”
where “column”