w3d1 Flashcards
SQL: How is an unknown value represented?
NULL
What does NULL represent?
An unknown value
How do you test to see if something matches (or doesn’t match) with NULL?
IS NULL
IS NOT NULL
How do conditional statements work in SQL?
CASE statements
What’s the general CASE statement syntax?
CASE WHEN condition_1 THEN result_1 WHEN condition_2 THEN result_2 ... [ELSE result_n] END;
What’s the simple CASE statement syntax?
CASE expression WHEN value_1 THEN result_1 WHEN value_2 THEN result_2 ... ELSE result_n END;
What does COALESCE do?
It selects the first non-NULL argument from its list.
How do you select the first non-NULL argument from a list?
COALESCE
What are the rails conventions for table names?
snake_case
pluralized
What are the rails conventions for foreign ids?
single_form_of_table + _id
Example:
tablename is bands
foreign id is band_id
What are some of SQL’s data types?
8-9: 5 stars
6-7: 4 stars
4-5: 3 stars
1-3: 1 star
BOOLEAN INT FLOAT VARCHAR(255) TEXT BLOB DATE DATETIME TIME BLOB
What are the 4 main SQL data manipulation operators?
SELECT
INSERT
UPDATE
DELETE
What’s the basic SELECT structure?
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)
;
What’s the basic INSERT structure?
INSERT INTO table_name (column names) VALUES (values) ;
What’s the basic UPDATE structure?
UPDATE table_name SET col_name1 = value1, col_name2 = value2, ... WHERE conditions ;