-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtopic_7_transactions.sql
34 lines (22 loc) · 1.06 KB
/
topic_7_transactions.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
## transactions:
##ACID (atomicity, consistency, isolation, durability)
use sql_store;
start transaction;
insert into orders (customer_id, order_date, status)
values (1, '2019-01-01', 1);
insert into order_items
values (last_insert_id(), 1, 1, 1);
commit;
# rollback;
## concurrency and locking:
show variables like 'transaction_isolation%';
set transaction isolation level serializable; # only works for next transaction
set session transaction isolation level serializable; # work for all transactions in the current session.
set global transaction isolation level serializable; # all transactions in all sessions.
## read uncommitted -> dirty reads (read uncommited changes by other session)
set transaction isolation level read uncommitted;
## read committed -> unrepeatable reads (repeated read of data can change while other session changes the data)
set transaction isolation level read committed;
## repeatable read
set transaction isolation level repeatable read;
set transaction isolation level serializable; # transaction will wait for other stansactions end.