w3d1 Flashcards

1
Q

SQL: How is an unknown value represented?

A

NULL

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

What does NULL represent?

A

An unknown value

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

How do you test to see if something matches (or doesn’t match) with NULL?

A

IS NULL

IS NOT NULL

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

How do conditional statements work in SQL?

A

CASE statements

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

What’s the general CASE statement syntax?

A
CASE
WHEN condition_1 THEN result_1
WHEN condition_2 THEN result_2
...
[ELSE result_n]
END;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What’s the simple CASE statement syntax?

A
CASE expression
WHEN value_1 THEN
result_1
WHEN value_2 THEN
result_2
...
ELSE
result_n
END;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does COALESCE do?

A

It selects the first non-NULL argument from its list.

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

How do you select the first non-NULL argument from a list?

A

COALESCE

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

What are the rails conventions for table names?

A

snake_case

pluralized

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

What are the rails conventions for foreign ids?

A

single_form_of_table + _id

Example:
tablename is bands
foreign id is band_id

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

What are some of SQL’s data types?

8-9: 5 stars
6-7: 4 stars
4-5: 3 stars
1-3: 1 star

A
BOOLEAN
INT
FLOAT
VARCHAR(255)
TEXT
BLOB
DATE
DATETIME
TIME
BLOB
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the 4 main SQL data manipulation operators?

A

SELECT
INSERT
UPDATE
DELETE

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

What’s the basic SELECT structure?

A

SELECT
one or more columns (or all cols with *)
FROM
one (or more tables, joined with JOIN)
WHERE
one (or more conditions, joined with AND/OR)
;

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

What’s the basic INSERT structure?

A
INSERT INTO
table_name (column names)
VALUES
(values)
;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What’s the basic UPDATE structure?

A
UPDATE
table_name
SET
col_name1 = value1,
col_name2 = value2, 
...
WHERE
conditions
;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What’s the basic DELETE syntax?

A
DELETE FROM
table_name
WHERE
conditions
;
17
Q

What’s the basic table creation syntax for a user with name, birth_date and address?

A
CREATE TABLE table_name (
 id INTEGER PRIMARY KEY,
name VARCHAR(100 NOT NULL,
birth_date DATE,
address VARCHAR(255)
);
18
Q

What’s the basic JOIN syntax?

A
SELECT
table1.colname, table2.colname
FROM
table1
JOIN
table2 ON table1.foreign_id = table2.id;
19
Q

What’s the 8-step order of operations of a SELECT query?

A
FROM and JOIN
WHERE
GROUP BY
HAVING
SELECT
DISTINCT
ORDER BY
LIMIT / OFFSET