SQL Flashcards

1
Q

What is SQL and how is it different from languages like JavaScript?

A

SQL is declarative - programmer describes results they want and the computer figures it out

JavaScript is imperative - programmer writes the machine instructions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you retrieve specific columns from a database table?

A

Select “column”,
“column”
From “row”;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you filter rows based on some specific criteria?

A

where “column“ = ‘text value’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the benefits of formatting your SQL?

A

To lessen complexity

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are four comparison operators that can be used in a where clause?

A

Less than, greater than, equal, not equal

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you limit the number of rows returned in a result set?

A

limit #

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you retrieve all columns from a database table?

A

universal *

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you control the sort order of a result set?

A

Order by “column” (desc) or (asc)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you add a row to a SQL table?

A

insert into “table” (“column”, “column”)
values (‘value’, value’);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a tuple?

A

a list of values in SQL

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do you add multiple rows to a SQL table at once?

A

comma separated list of tuples.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do you get back the row being inserted into a table without a separate select statement?

A

returning * or comma-separated column names;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do you update rows in a database table?

A

update “table”
set “column” = value
where “target” = target value;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Why is it important to include a where clause in your update statements?

A

to target a specific row, others all rows would be updated.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How do you delete rows from a database table?

A

delete
from “table”
where “target” = “target value”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do you accidentally delete all rows from a table?

A

by leaving out the “where” clause.

17
Q

What is a foreign key?

A

a value in one table that’s the same as value of another table to link them.

18
Q

How do you join two SQL tables?

A

from “table” join “table” using (“foreign key”)

19
Q

How do you temporarily rename columns or tables in a SQL statement?

A

select “table”.”column” as “alias”

20
Q

What are some examples of aggregate functions?

A

max(), avg (), count(), min(), sum(), every()

21
Q

What is the purpose of a group by clause?

A

to separate rows into groups and perform aggregate functions on just those groups of rows, rather than every row in table.