Lecture 9 Flashcards
How to do union with SQL?
(SELECT * FROM R) UNION (SELECT * FROM R);
If duplicates then use UNION ALL
How to insert in SQL?
INSERT INTO R(A1, …, An) VALUES (.., …) … ;
How to delete in SQL?
DELETE FROM R WHERE C;
How to update in SQL?
UPDATE table_name
SET column1 = value1, column2 = value2, …
WHERE condition;
You can also change using || and including other values.
What is the goal of a transaction?
To make sure that certain queries are processed in a serializable way. It also makes sure that a transaction is either completed or not.
How to start and end a transaction?
Start: START TRANSACTION
Abort: ROLLBACK;
Finish: COMMIT;
How to set read-only transaction?
SET TRANSACTION READ ONLY;
What is a Dirty read?
Uses data that may be lost in the end because of ROLLBACK;
What are the 4 isolation levels?
- Read Uncommited, 2. Read committed, 3. Repeatable read, 4. Serializable
What can each isolation level do?
Read uncommitted: dirty reads, non-repeatable, phantoms. Read committed: non-repeatable, phantoms. Repeatable read: phantoms. Serializable: None.
Phantom: Read new rows
What is non-repeatable?
New data may enter in the transaction
What is serialiazable?
New data cannot be inserted, or updated until transaction is completed.
What is GREATEST?
Just maximum for multiple rows. Similar to LEAST() for min.
How to do switch case in SQL?
e.g. CASE A
WHEN A = ‘a’ THEN ‘b’
How to use LIMIT?
LIMIT returns at most the number of tuples that is placed after it.
and
LIMIT 10, 100 skips the first 10 then returns the next 100.