Head First SQL Flashcards
Does this work: WHERE second = “Orange Juice”;
No. SQL expects single quote
if amount is DEC, does this work: WHERE amount = “1.5”
Yes. RDBMS is forgiving
Types with quotes
CHAR, VARCHAR, DATE, DATETIME, TIME, TIMESTAMP, BLOB
Types without quotes
DEC INT
single quote is a special character
' or ‘’
Not equal
<>
Find all the cities ending with CA
WHERE location LIKE ‘%CA’. % stands for any number of unknown characters
wild card in LIKE which stands for only one character
_
between two numbers
calories BETWEEN 30 AND 60
Write a query that will SELECT the names of drinks that begins with letters G through O
WHERE drink_name BETWEEN ‘G’ AND ‘O’
rating is ‘innovative’ or ‘fabulous‘
WHERE rating in (‘innovative’, ‘fabulous’)
rating is not ‘innovative’ and ‘fabulous’
WHERE rating not in (‘innovative’, ‘fabulous’)
Difference:
WHERE NOT main IN ( );
WHERE main NOT IN ( );
The same
Find IS not NULL
WHERE NOT main IS NULL; or
WHERE main IS NOT NULL
DELETE records
DELECT FROM
UPDATE a table
UPDATE … SET …
Primary key requirement
- Not NULL 2. can’t be changed
Normal table
- Atomic 2. Primary key
Return the CREATE TABLE statement
SHOW CREATE TABLE my_contracts;