Head First SQL Flashcards
(49 cards)
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;
To CREATE TABLE
CREATE TABLE my_contract (last_name VARCHAR(20) )
AUTO_INCREMENT
Automatically fill the column with a value that starts on row 1 with increment of 1 for every new row
Add a primary key to an existing table
ALTER TABLE XX
ADD COLUMN contact_id INT NOT NULL AUTO_INCREMENT
PRIMARY KEY (contact_id)
Renaming the table
ALTER TABLE projeckts RENAME TO project_list
Remove the primary key designation without changing the data?
ALTER TABLE XX DROP PRIMARY KEY;