Xử lý lỗi

Giao dịch và Xử lý Lỗi trong PostgreSQL

Jason Myers

Principal Engineer

Lỗi là điều thường gặp

Cập nhật nhầm Biscuits

UPDATE cookies SET quantity = 13 WHERE name = 'Biscuits';

Sửa để cập nhật Biscotti

UPDATE cookies SET quantity = 1 WHERE name = 'Biscuits';

UPDATE cookies SET quantity = 13 WHERE name = 'Biscotti';
Giao dịch và Xử lý Lỗi trong PostgreSQL

Hoàn tác lỗi (ROLLBACK)

BEGIN TRANSACTION

UPDATE cookies SET quantity = 13 WHERE name = 'Biscuits';
ROLLBACK;
SELECT quantity FROM cookies where name = 'Biscuits';
13
Giao dịch và Xử lý Lỗi trong PostgreSQL

Hoàn tác nhiều câu lệnh

BEGIN TRANSACTION;

UPDATE cookies SET deliciousness = 111 where name = 'Cats Tongue';

UPDATE cookies SET deliciousness = 8 where name = 'Gingerbread';

ROLLBACK;
SELECT name, deliciousness FROM cookies where name in ('Cats Tongue', 'Gingerbread');
'Cats Tongue'  10
'Gingerbread'   9
Giao dịch và Xử lý Lỗi trong PostgreSQL

Hãy luyện tập!

Giao dịch và Xử lý Lỗi trong PostgreSQL

Preparing Video For Download...