Lecture 9 Flashcards

1
Q

How to do union with SQL?

A

(SELECT * FROM R) UNION (SELECT * FROM R);

If duplicates then use UNION ALL

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

How to insert in SQL?

A

INSERT INTO R(A1, …, An) VALUES (.., …) … ;

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

How to delete in SQL?

A

DELETE FROM R WHERE C;

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

How to update in SQL?

A

UPDATE table_name
SET column1 = value1, column2 = value2, …
WHERE condition;

You can also change using || and including other values.

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

What is the goal of a transaction?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to start and end a transaction?

A

Start: START TRANSACTION
Abort: ROLLBACK;
Finish: COMMIT;

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

How to set read-only transaction?

A

SET TRANSACTION READ ONLY;

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

What is a Dirty read?

A

Uses data that may be lost in the end because of ROLLBACK;

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

What are the 4 isolation levels?

A
  1. Read Uncommited, 2. Read committed, 3. Repeatable read, 4. Serializable
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What can each isolation level do?

A

Read uncommitted: dirty reads, non-repeatable, phantoms. Read committed: non-repeatable, phantoms. Repeatable read: phantoms. Serializable: None.

Phantom: Read new rows

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

What is non-repeatable?

A

New data may enter in the transaction

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

What is serialiazable?

A

New data cannot be inserted, or updated until transaction is completed.

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

What is GREATEST?

A

Just maximum for multiple rows. Similar to LEAST() for min.

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

How to do switch case in SQL?

A

e.g. CASE A

WHEN A = ‘a’ THEN ‘b’

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

How to use LIMIT?

A

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.

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

How to randomly select data.

A

SELECT * FROM R WHERE RAND() < 0.1;

0.1 is example, thus selects 10% of all values.