{"id":80857,"date":"2024-11-01T16:02:42","date_gmt":"2024-11-01T09:02:42","guid":{"rendered":"https:\/\/itviec.com\/blog\/?p=80857"},"modified":"2024-11-01T16:02:42","modified_gmt":"2024-11-01T09:02:42","slug":"transaction-trong-database-la-gi","status":"publish","type":"post","link":"https:\/\/itviec.com\/blog\/transaction-trong-database-la-gi\/","title":{"rendered":"Transaction trong database: C\u00e1c thao t\u00e1c c\u01a1 b\u1ea3n v\u1edbi transaction"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">N\u1ed9i dung b\u00e0i vi\u1ebft<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/itviec.com\/blog\/transaction-trong-database-la-gi\/#Transaction_trong_database_la_gi\" >Transaction trong database l\u00e0 g\u00ec?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/itviec.com\/blog\/transaction-trong-database-la-gi\/#Vong_doi_cua_mot_transaction_trong_database\" >V\u00f2ng \u0111\u1eddi c\u1ee7a m\u1ed9t transaction trong database<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/itviec.com\/blog\/transaction-trong-database-la-gi\/#Cac_trang_thai_cua_transaction_trong_database\" >C\u00e1c tr\u1ea1ng th\u00e1i c\u1ee7a transaction trong database<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/itviec.com\/blog\/transaction-trong-database-la-gi\/#Thu_tu_thuc_hien_transaction_trong_database\" >Th\u1ee9 t\u1ef1 th\u1ef1c hi\u1ec7n transaction trong database\u00a0<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/itviec.com\/blog\/transaction-trong-database-la-gi\/#Cac_thao_tac_co_ban_voi_transaction_trong_database\" >C\u00e1c thao t\u00e1c c\u01a1 b\u1ea3n v\u1edbi transaction trong database<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/itviec.com\/blog\/transaction-trong-database-la-gi\/#Uu_diem_cua_transaction_trong_quan_ly_du_lieu\" >\u01afu \u0111i\u1ec3m c\u1ee7a transaction trong qu\u1ea3n l\u00fd d\u1eef li\u1ec7u<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/itviec.com\/blog\/transaction-trong-database-la-gi\/#Cau_hoi_thuong_gap_ve_transaction_trong_database\" >C\u00e2u h\u1ecfi th\u01b0\u1eddng g\u1eb7p v\u1ec1 transaction trong database<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/itviec.com\/blog\/transaction-trong-database-la-gi\/#Tong_ket_transaction_trong_database\" >T\u1ed5ng k\u1ebft transaction trong database<\/a><\/li><\/ul><\/nav><\/div>\n<p><em><strong>MySQL, MariaDB, PostgreSQL, Oracle Database v\u00e0 Microsoft SQL Server l\u00e0 nh\u1eefng h\u1ec7 qu\u1ea3n tr\u1ecb c\u01a1 s\u1edf d\u1eef li\u1ec7u quan h\u1ec7 (<a href=\"https:\/\/itviec.com\/blog\/rdbms-la-gi\/\" target=\"_blank\" rel=\"noopener\">RDBMS<\/a>) ph\u1ed5 bi\u1ebfn nh\u1ea5t hi\u1ec7n nay. \u0110i\u1ec3m chung c\u1ee7a t\u1ea5t c\u1ea3 c\u00e1c h\u1ec7 th\u1ed1ng n\u00e0y l\u00e0 ch\u00fang \u0111\u1ec1u l\u00e0 c\u01a1 s\u1edf d\u1eef li\u1ec7u giao d\u1ecbch (transactional databases). \u0110i\u1ec1u n\u00e0y c\u00f3 ngh\u0129a l\u00e0 c\u00e1c h\u1ec7 th\u1ed1ng n\u00e0y cung c\u1ea5p c\u00e1c transaction \u0111\u1ec3 \u0111\u1ea3m b\u1ea3o t\u00ednh to\u00e0n v\u1eb9n v\u00e0 nh\u1ea5t qu\u00e1n c\u1ee7a d\u1eef li\u1ec7u. V\u00ec v\u1eady, vi\u1ec7c hi\u1ec3u r\u00f5 transaction trong database l\u00e0 g\u00ec v\u00e0 c\u00e1ch ch\u00fang ho\u1ea1t \u0111\u1ed9ng trong c\u01a1 s\u1edf d\u1eef li\u1ec7u quan h\u1ec7 l\u00e0 v\u00f4 c\u00f9ng quan tr\u1ecdng.<\/strong><\/em><\/p>\n<p><span style=\"font-weight: 400;\">\u0110\u1ecdc b\u00e0i vi\u1ebft n\u00e0y \u0111\u1ec3 hi\u1ec3u r\u00f5 h\u01a1n v\u1ec1:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Transaction trong database l\u00e0 g\u00ec?<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Th\u1ee9 t\u1ef1 th\u1ef1c hi\u1ec7n transaction trong database<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">C\u00e1c thao t\u00e1c c\u01a1 b\u1ea3n v\u1edbi transaction<\/span><\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Transaction_trong_database_la_gi\"><\/span><b>Transaction trong database l\u00e0 g\u00ec?<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Transaction trong c\u01a1 s\u1edf d\u1eef li\u1ec7u l\u00e0 m\u1ed9t \u0111\u01a1n v\u1ecb logic bao g\u1ed3m m\u1ed9t ho\u1eb7c nhi\u1ec1u thao t\u00e1c \u0111\u01b0\u1ee3c th\u1ef1c hi\u1ec7n li\u00ean quan \u0111\u1ebfn vi\u1ec7c t\u1ea1o, c\u1eadp nh\u1eadt ho\u1eb7c truy xu\u1ea5t d\u1eef li\u1ec7u. C\u00e1c transaction \u0111\u1ea3m b\u1ea3o r\u1eb1ng c\u01a1 s\u1edf d\u1eef li\u1ec7u lu\u00f4n \u1edf tr\u1ea1ng th\u00e1i \u0111\u00e1ng tin c\u1eady v\u00e0 nh\u1ea5t qu\u00e1n.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Khi m\u1ed9t transaction ho\u00e0n t\u1ea5t th\u00e0nh c\u00f4ng, d\u1eef li\u1ec7u s\u1ebd \u0111\u01b0\u1ee3c c\u1eadp nh\u1eadt nh\u01b0 \u0111\u00e3 ch\u1ec9 \u0111\u1ecbnh v\u00e0 qu\u00e1 tr\u00ecnh n\u00e0y \u0111\u01b0\u1ee3c g\u1ecdi l\u00e0 &#8220;commit&#8221;. Tuy nhi\u00ean, n\u1ebfu m\u1ed9t b\u01b0\u1edbc n\u00e0o \u0111\u00f3 trong transaction g\u1eb7p l\u1ed7i, t\u1ea5t c\u1ea3 c\u00e1c b\u01b0\u1edbc tr\u01b0\u1edbc \u0111\u00f3 s\u1ebd b\u1ecb h\u1ee7y b\u1ecf v\u00e0 d\u1eef li\u1ec7u s\u1ebd \u0111\u01b0\u1ee3c ho\u00e0n nguy\u00ean v\u1ec1 tr\u1ea1ng th\u00e1i ban \u0111\u1ea7u gi\u1ed1ng nh\u01b0 tr\u01b0\u1edbc khi th\u1ef1c hi\u1ec7n c\u00e1c h\u00e0nh \u0111\u1ed9ng trong transaction. Qu\u00e1 tr\u00ecnh n\u00e0y \u0111\u01b0\u1ee3c g\u1ecdi l\u00e0 &#8220;rollback&#8221;.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">M\u1ed9t transaction trong CSDL k\u1ebft th\u00fac b\u1eb1ng vi\u1ec7c commit ho\u1eb7c rollback, \u0111\u1ea3m b\u1ea3o r\u1eb1ng d\u1eef li\u1ec7u lu\u00f4n tu\u00e2n th\u1ee7 theo c\u00e1c thu\u1ed9c t\u00ednh ACID, bao g\u1ed3m: Atomicity (t\u00ednh nguy\u00ean t\u1eed), Consistency (t\u00ednh nh\u1ea5t qu\u00e1n), Isolation (t\u00ednh \u0111\u1ed9c l\u1eadp) v\u00e0 Durability (t\u00ednh b\u1ec1n v\u1eefng). \u0110\u00e2y l\u00e0 nh\u1eefng nguy\u00ean t\u1eafc quan tr\u1ecdng \u0111\u1ec3 \u0111\u1ea3m b\u1ea3o s\u1ef1 an to\u00e0n v\u00e0 \u1ed5n \u0111\u1ecbnh cho d\u1eef li\u1ec7u trong qu\u00e1 tr\u00ecnh x\u1eed l\u00fd giao d\u1ecbch.<\/span><\/p>\n<h3><b>T\u00ednh ch\u1ea5t ACID c\u1ee7a transaction<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Trong h\u1ec7 qu\u1ea3n tr\u1ecb c\u01a1 s\u1edf d\u1eef li\u1ec7u (DBMS), c\u00e1c transaction ph\u1ea3i tu\u00e2n theo b\u1ed1n t\u00ednh ch\u1ea5t ACID \u0111\u1ec3 \u0111\u1ea3m b\u1ea3o t\u00ednh to\u00e0n v\u1eb9n c\u1ee7a d\u1eef li\u1ec7u trong tr\u01b0\u1eddng h\u1ee3p c\u00f3 l\u1ed7i ho\u1eb7c s\u1ef1 c\u1ed1 x\u1ea3y ra. C\u1ee5 th\u1ec3, ACID bao g\u1ed3m c\u00e1c t\u00ednh ch\u1ea5t sau:<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Atomicity (T\u00ednh nguy\u00ean t\u1eed)<\/b><span style=\"font-weight: 400;\">: T\u00ednh ch\u1ea5t n\u00e0y \u0111\u1ea3m b\u1ea3o r\u1eb1ng t\u1ea5t c\u1ea3 c\u00e1c thao t\u00e1c trong m\u1ed9t transaction ph\u1ea3i \u0111\u01b0\u1ee3c th\u1ef1c hi\u1ec7n ho\u00e0n to\u00e0n, ho\u1eb7c kh\u00f4ng th\u1ef1c hi\u1ec7n g\u00ec c\u1ea3. \u0110i\u1ec1u n\u00e0y c\u00f3 ngh\u0129a l\u00e0 transaction l\u00e0 m\u1ed9t \u0111\u01a1n v\u1ecb kh\u00f4ng th\u1ec3 chia nh\u1ecf. N\u1ebfu c\u00f3 b\u1ea5t k\u1ef3 thao t\u00e1c n\u00e0o th\u1ea5t b\u1ea1i, to\u00e0n b\u1ed9 transaction s\u1ebd b\u1ecb h\u1ee7y v\u00e0 c\u00e1c thay \u0111\u1ed5i tr\u01b0\u1edbc \u0111\u00f3 s\u1ebd b\u1ecb rollback \u0111\u1ec3 ng\u0103n ch\u1eb7n vi\u1ec7c c\u1eadp nh\u1eadt kh\u00f4ng ho\u00e0n ch\u1ec9nh l\u00ean c\u01a1 s\u1edf d\u1eef li\u1ec7u.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Consistency (T\u00ednh nh\u1ea5t qu\u00e1n)<\/b><span style=\"font-weight: 400;\">: B\u1ea5t k\u1ef3 transaction n\u00e0o c\u0169ng ph\u1ea3i \u0111\u1ea3m b\u1ea3o r\u1eb1ng sau khi ho\u00e0n th\u00e0nh, c\u01a1 s\u1edf d\u1eef li\u1ec7u v\u1eabn \u1edf tr\u1ea1ng th\u00e1i nh\u1ea5t qu\u00e1n theo c\u00e1c quy t\u1eafc v\u00e0 r\u00e0ng bu\u1ed9c hi\u1ec7n c\u00f3 trong CSDL (kh\u00f3a ch\u00ednh, kh\u00f3a ngo\u1ea1i, unique,..). N\u1ebfu c\u01a1 s\u1edf d\u1eef li\u1ec7u \u1edf tr\u1ea1ng th\u00e1i nh\u1ea5t qu\u00e1n tr\u01b0\u1edbc khi transaction di\u1ec5n ra, n\u00f3 ph\u1ea3i ti\u1ebfp t\u1ee5c \u1edf tr\u1ea1ng th\u00e1i nh\u1ea5t qu\u00e1n sau khi transaction ho\u00e0n t\u1ea5t, b\u1ea5t k\u1ec3 transaction th\u00e0nh c\u00f4ng hay th\u1ea5t b\u1ea1i.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Isolation (T\u00ednh c\u00f4 l\u1eadp)<\/b><span style=\"font-weight: 400;\">: T\u00ednh ch\u1ea5t n\u00e0y \u0111\u1ea3m b\u1ea3o r\u1eb1ng m\u1ed7i transaction \u0111\u01b0\u1ee3c th\u1ef1c hi\u1ec7n nh\u01b0 th\u1ec3 n\u00f3 l\u00e0 transaction duy nh\u1ea5t \u0111ang ch\u1ea1y tr\u00ean h\u1ec7 th\u1ed1ng. D\u1eef li\u1ec7u \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng trong m\u1ed9t transaction ch\u01b0a ho\u00e0n th\u00e0nh s\u1ebd kh\u00f4ng b\u1ecb thay \u0111\u1ed5i b\u1edfi c\u00e1c transaction kh\u00e1c. M\u1eb7c kh\u00e1c, d\u1eef li\u1ec7u \u0111\u00e3 \u0111\u01b0\u1ee3c thay \u0111\u1ed5i trong transaction nh\u01b0ng ch\u01b0a commit s\u1ebd kh\u00f4ng \u0111\u01b0\u1ee3c hi\u1ec3n th\u1ecb \u1edf c\u00e1c l\u1ec7nh truy v\u1ea5n kh\u00e1c. \u0110i\u1ec1u n\u00e0y ng\u0103n ng\u1eeba c\u00e1c xung \u0111\u1ed9t khi c\u00f3 nhi\u1ec1u transaction \u0111\u1ed3ng th\u1eddi thao t\u00e1c tr\u00ean c\u00f9ng m\u1ed9t d\u1eef li\u1ec7u.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Durability (T\u00ednh b\u1ec1n v\u1eefng)<\/b><span style=\"font-weight: 400;\">: Sau khi m\u1ed9t transaction ho\u00e0n t\u1ea5t v\u00e0 \u0111\u01b0\u1ee3c commit, c\u00e1c thay \u0111\u1ed5i c\u1ee7a n\u00f3 s\u1ebd \u0111\u01b0\u1ee3c l\u01b0u v\u0129nh vi\u1ec5n v\u00e0o c\u01a1 s\u1edf d\u1eef li\u1ec7u, ngay c\u1ea3 khi c\u00f3 s\u1ef1 c\u1ed1 h\u1ec7 th\u1ed1ng x\u1ea3y ra sau \u0111\u00f3. N\u1ebfu c\u01a1 s\u1edf d\u1eef li\u1ec7u b\u1ecb l\u1ed7i sau khi transaction ho\u00e0n th\u00e0nh nh\u01b0ng tr\u01b0\u1edbc khi d\u1eef li\u1ec7u \u0111\u01b0\u1ee3c ghi l\u00ean \u0111\u0129a, h\u1ec7 th\u1ed1ng s\u1ebd \u0111\u1ea3m b\u1ea3o r\u1eb1ng c\u00e1c thay \u0111\u1ed5i c\u1ee7a transaction v\u1eabn \u0111\u01b0\u1ee3c \u00e1p d\u1ee5ng khi h\u1ec7 th\u1ed1ng tr\u1edf l\u1ea1i ho\u1ea1t \u0111\u1ed9ng.<\/span><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">M\u1eb7c d\u00f9 ACID gi\u00fap \u0111\u1ea3m b\u1ea3o t\u00ednh to\u00e0n v\u1eb9n v\u00e0 an to\u00e0n c\u1ee7a d\u1eef li\u1ec7u, vi\u1ec7c \u0111\u1ea3m b\u1ea3o c\u00e1c t\u00ednh ch\u1ea5t n\u00e0y th\u01b0\u1eddng \u0111i k\u00e8m v\u1edbi m\u1ed9t c\u00e1i gi\u00e1 v\u1ec1 hi\u1ec7u su\u1ea5t. M\u1ed9t s\u1ed1 DBMS nh\u01b0 MySQL cho ph\u00e9p v\u00f4 hi\u1ec7u h\u00f3a m\u1ed9t ph\u1ea7n t\u00ednh ch\u1ea5t ACID \u0111\u1ec3 c\u1ea3i thi\u1ec7n t\u1ed1c \u0111\u1ed9 b\u1eb1ng c\u00e1ch \u0111i\u1ec1u ch\u1ec9nh m\u1ed9t s\u1ed1 th\u00f4ng s\u1ed1 h\u1ec7 th\u1ed1ng th\u00f4ng qua vi\u1ec7c \u0111i\u1ec1u ch\u1ec9nh c\u00e1c tham s\u1ed1 h\u1ec7 th\u1ed1ng (v\u00ed d\u1ee5 nh\u01b0 t\u1eaft ch\u1ebf \u0111\u1ed9 autocommit ho\u1eb7c ghi nh\u1eadt k\u00fd giao d\u1ecbch).<\/span><\/p>\n<h3><b>T\u1ea1i sao database transaction l\u1ea1i c\u1ea7n thi\u1ebft?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">H\u1ec7 th\u1ed1ng c\u00f3 th\u1ec3 g\u1eb7p s\u1ef1 c\u1ed1 b\u1ea5t ng\u1edd nh\u01b0 m\u1ea5t \u0111i\u1ec7n, l\u1ed7i ph\u1ea7n m\u1ec1m, l\u1ed7i ph\u1ea7n c\u1ee9ng ho\u1eb7c c\u00e1c l\u1ed7i x\u1ea3y ra khi c\u00e1c thao t\u00e1c ghi, c\u1eadp nh\u1eadt d\u1eef li\u1ec7u trong nh\u1eefng t\u00ecnh hu\u1ed1ng n\u00e0y, transaction \u0111\u1ea3m b\u1ea3o r\u1eb1ng k\u1ebft qu\u1ea3 c\u1ee7a d\u1eef li\u1ec7u v\u1eabn \u0111\u00e1ng tin c\u1eady v\u00e0 nh\u1ea5t qu\u00e1n. \u0110i\u1ec1u n\u00e0y c\u00f3 ngh\u0129a l\u00e0 tr\u1ea1ng th\u00e1i c\u1ee7a c\u01a1 s\u1edf d\u1eef li\u1ec7u s\u1ebd ph\u1ea3n \u00e1nh t\u1ea5t c\u1ea3 c\u00e1c thay \u0111\u1ed5i \u0111\u01b0\u1ee3c commit tr\u01b0\u1edbc th\u1eddi \u0111i\u1ec3m x\u1ea3y ra s\u1ef1 c\u1ed1 v\u00e0 nh\u1eefng transaction \u0111ang th\u1ef1c hi\u1ec7n t\u1ea1i th\u1eddi \u0111i\u1ec3m \u0111\u00f3 s\u1ebd \u0111\u01b0\u1ee3c rollback s\u1ea1ch s\u1ebd \u0111\u1ec3 tr\u00e1nh sai s\u00f3t.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Khi c\u00f3 nhi\u1ec1u y\u00eau c\u1ea7u \u0111\u1ed3ng th\u1eddi t\u00e1c \u0111\u1ed9ng l\u00ean m\u00e1y ch\u1ee7 c\u01a1 s\u1edf d\u1eef li\u1ec7u v\u00e0 thao t\u00e1c tr\u00ean c\u00f9ng m\u1ed9t d\u1eef li\u1ec7u, transaction s\u1ebd c\u00f4 l\u1eadp c\u00e1c y\u00eau c\u1ea7u n\u00e0y v\u1edbi nhau \u0111\u1ec3 tr\u00e1nh xung \u0111\u1ed9t. \u0110i\u1ec1u n\u00e0y \u0111\u1ea3m b\u1ea3o r\u1eb1ng c\u00e1c thay \u0111\u1ed5i \u0111\u01b0\u1ee3c th\u1ef1c hi\u1ec7n \u0111\u1ed9c l\u1eadp v\u00e0 kh\u00f4ng g\u00e2y \u1ea3nh h\u01b0\u1edfng l\u1eabn nhau, gi\u00fap duy tr\u00ec t\u00ednh to\u00e0n v\u1eb9n c\u1ee7a d\u1eef li\u1ec7u.<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Vong_doi_cua_mot_transaction_trong_database\"><\/span><b>V\u00f2ng \u0111\u1eddi c\u1ee7a m\u1ed9t transaction trong database<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">V\u00f2ng \u0111\u1eddi c\u1ee7a m\u1ed9t transaction trong c\u01a1 s\u1edf d\u1eef li\u1ec7u giao d\u1ecbch (transactional database) tr\u1ea3i qua t\u1eeb khi b\u1eaft \u0111\u1ea7u \u0111\u1ebfn khi k\u1ebft th\u00fac qua c\u00e1c b\u01b0\u1edbc nh\u01b0 sau:<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Transaction b\u1eaft \u0111\u1ea7u<\/b><span style=\"font-weight: 400;\">: H\u1ec7 th\u1ed1ng c\u01a1 s\u1edf d\u1eef li\u1ec7u chu\u1ea9n b\u1ecb m\u1ecdi th\u1ee9 c\u1ea7n thi\u1ebft \u0111\u1ec3 th\u1ef1c hi\u1ec7n transaction.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Th\u1ef1c thi c\u00e1c truy v\u1ea5n trong transaction<\/b><span style=\"font-weight: 400;\">: \u0110\u00e2y l\u00e0 giai \u0111o\u1ea1n thao t\u00e1c d\u1eef li\u1ec7u, bao g\u1ed3m vi\u1ec7c \u0111\u1ecdc v\u00e0 ghi. D\u1eef li\u1ec7u s\u1ebd \u0111\u01b0\u1ee3c l\u01b0u tr\u1eef t\u1ea1m th\u1eddi trong b\u1ed9 nh\u1edb v\u00e0 ch\u01b0a commit v\u00e0o CSDL.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Transaction \u0111\u01b0\u1ee3c commit n\u1ebfu kh\u00f4ng c\u00f3 l\u1ed7i x\u1ea3y ra<\/b><span style=\"font-weight: 400;\">: N\u1ebfu t\u1ea5t c\u1ea3 c\u00e1c thao t\u00e1c \u0111\u01b0\u1ee3c th\u1ef1c hi\u1ec7n th\u00e0nh c\u00f4ng, transaction s\u1ebd \u0111\u01b0\u1ee3c k\u1ebft th\u00fac v\u1edbi vi\u1ec7c commit, t\u1ee9c l\u00e0 c\u00e1c thay \u0111\u1ed5i tr\u1edf n\u00ean v\u0129nh vi\u1ec5n trong c\u01a1 s\u1edf d\u1eef li\u1ec7u v\u00e0 kh\u00f4ng th\u1ec3 quay l\u1ea1i.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Transaction rollback n\u1ebfu x\u1ea3y ra l\u1ed7i<\/b><span style=\"font-weight: 400;\">: N\u1ebfu c\u00f3 l\u1ed7i trong qu\u00e1 tr\u00ecnh th\u1ef1c hi\u1ec7n, t\u1ea5t c\u1ea3 c\u00e1c thay \u0111\u1ed5i tr\u01b0\u1edbc \u0111\u00f3 s\u1ebd b\u1ecb h\u1ee7y b\u1ecf v\u00e0 d\u1eef li\u1ec7u \u0111\u01b0\u1ee3c tr\u1ea3 v\u1ec1 tr\u1ea1ng th\u00e1i ban \u0111\u1ea7u tr\u01b0\u1edbc khi transaction b\u1eaft \u0111\u1ea7u.<\/span><\/li>\n<\/ol>\n<h2><span class=\"ez-toc-section\" id=\"Cac_trang_thai_cua_transaction_trong_database\"><\/span><b>C\u00e1c tr\u1ea1ng th\u00e1i c\u1ee7a transaction trong database<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Transaction trong c\u01a1 s\u1edf d\u1eef li\u1ec7u tr\u1ea3i qua nhi\u1ec1u tr\u1ea1ng th\u00e1i trong su\u1ed1t v\u00f2ng \u0111\u1eddi c\u1ee7a n\u00f3 \u0111\u1ec3 \u0111\u1ea3m b\u1ea3o d\u1eef li\u1ec7u \u0111\u01b0\u1ee3c x\u1eed l\u00fd an to\u00e0n v\u00e0 nh\u1ea5t qu\u00e1n. Qu\u00e1 tr\u00ecnh ho\u1ea1t \u0111\u1ed9ng c\u1ee7a m\u1ed9t transaction th\u01b0\u1eddng bao g\u1ed3m c\u00e1c tr\u1ea1ng th\u00e1i sau:<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Tr\u1ea1ng th\u00e1i ho\u1ea1t \u0111\u1ed9ng (Active)<\/b><span style=\"font-weight: 400;\">: \u0110\u00e2y l\u00e0 tr\u1ea1ng th\u00e1i \u0111\u1ea7u ti\u00ean khi m\u1ed9t transaction b\u01b0\u1edbc v\u00e0o giai \u0111o\u1ea1n Begin Transaction. L\u00fac n\u00e0y transaction s\u1eb5n s\u00e0ng \u0111\u1ec3 th\u1ef1c hi\u1ec7n c\u00e1c l\u1ec7nh nh\u01b0 \u0111\u1ecdc ho\u1eb7c ghi d\u1eef li\u1ec7u. Transaction \u1edf tr\u1ea1ng th\u00e1i n\u00e0y cho \u0111\u1ebfn khi ho\u00e0n t\u1ea5t c\u00e1c thao t\u00e1c.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Tr\u1ea1ng th\u00e1i m\u1ed9t ph\u1ea7n \u0111\u01b0\u1ee3c commit (Partially Committed)<\/b><span style=\"font-weight: 400;\">: Trong tr\u1ea1ng th\u00e1i n\u00e0y, c\u00e1c thay \u0111\u1ed5i \u0111\u00e3 \u0111\u01b0\u1ee3c th\u1ef1c hi\u1ec7n nh\u01b0ng ch\u1ec9 \u0111\u01b0\u1ee3c l\u01b0u tr\u1eef trong\u00a0 b\u1ed9 nh\u1edb t\u1ea1m th\u1eddi v\u00e0 ch\u01b0a \u0111\u01b0\u1ee3c ghi v\u00e0o c\u01a1 s\u1edf d\u1eef li\u1ec7u m\u1ed9t c\u00e1ch v\u0129nh vi\u1ec5n.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Tr\u1ea1ng th\u00e1i \u0111\u00e3 commit (Committed)<\/b><span style=\"font-weight: 400;\">: T\u1ea1i th\u1eddi \u0111i\u1ec3m n\u00e0y, t\u1ea5t c\u1ea3 c\u00e1c c\u1eadp nh\u1eadt c\u1ee7a transaction \u0111\u00e3 \u0111\u01b0\u1ee3c l\u01b0u tr\u1eef v\u0129nh vi\u1ec5n v\u00e0o c\u01a1 s\u1edf d\u1eef li\u1ec7u. Sau khi transaction \u0111\u01b0\u1ee3c commit, kh\u00f4ng th\u1ec3 th\u1ef1c hi\u1ec7n rollback \u0111\u1ec3 quay l\u1ea1i tr\u1ea1ng th\u00e1i tr\u01b0\u1edbc \u0111\u00f3.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Tr\u1ea1ng th\u00e1i th\u1ea5t b\u1ea1i (Failed)<\/b><span style=\"font-weight: 400;\">: N\u1ebfu transaction g\u1eb7p l\u1ed7i ho\u1eb7c b\u1ecb h\u1ee7y trong tr\u1ea1ng th\u00e1i ho\u1ea1t \u0111\u1ed9ng ho\u1eb7c m\u1ed9t ph\u1ea7n \u0111\u01b0\u1ee3c commit, n\u00f3 s\u1ebd chuy\u1ec3n sang tr\u1ea1ng th\u00e1i th\u1ea5t b\u1ea1i. Khi \u0111\u00f3, h\u1ec7 th\u1ed1ng s\u1ebd th\u1ef1c hi\u1ec7n rollback \u0111\u1ec3 \u0111\u1ea3m b\u1ea3o d\u1eef li\u1ec7u tr\u1edf v\u1ec1 tr\u1ea1ng th\u00e1i ban \u0111\u1ea7u, nh\u01b0 th\u1ec3 transaction ch\u01b0a t\u1eebng \u0111\u01b0\u1ee3c th\u1ef1c hi\u1ec7n.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Tr\u1ea1ng th\u00e1i k\u1ebft th\u00fac (Terminated)<\/b><span style=\"font-weight: 400;\">: \u0110\u00e2y l\u00e0 tr\u1ea1ng th\u00e1i cu\u1ed1i c\u00f9ng sau khi transaction \u0111\u01b0\u1ee3c commit ho\u1eb7c b\u1ecb rollback. Tr\u1ea1ng th\u00e1i n\u00e0y \u0111\u00e1nh d\u1ea5u k\u1ebft th\u00fac v\u00f2ng \u0111\u1eddi c\u1ee7a transaction.<\/span><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">V\u1edbi nh\u1eefng tr\u1ea1ng th\u00e1i n\u00e0y, transaction \u0111\u1ea3m b\u1ea3o r\u1eb1ng d\u1eef li\u1ec7u lu\u00f4n ch\u00ednh x\u00e1c v\u00e0 kh\u00f4ng b\u1ecb l\u1ed7i ngay c\u1ea3 khi h\u1ec7 th\u1ed1ng g\u1eb7p s\u1ef1 c\u1ed1, \u0111\u1ed3ng th\u1eddi ng\u0103n ch\u1eb7n xung \u0111\u1ed9t khi c\u00f3 nhi\u1ec1u y\u00eau c\u1ea7u \u0111\u1ed3ng th\u1eddi thay \u0111\u1ed5i d\u1eef li\u1ec7u c\u00f9ng m\u1ed9t l\u00fac.\u00a0<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Thu_tu_thuc_hien_transaction_trong_database\"><\/span><b>Th\u1ee9 t\u1ef1 th\u1ef1c hi\u1ec7n transaction trong database\u00a0<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Khi nhi\u1ec1u transaction \u0111\u01b0\u1ee3c y\u00eau c\u1ea7u th\u1ef1c hi\u1ec7n \u0111\u1ed3ng th\u1eddi trong c\u01a1 s\u1edf d\u1eef li\u1ec7u, th\u1ee9 t\u1ef1 th\u1ef1c hi\u1ec7n c\u00e1c transaction r\u1ea5t quan tr\u1ecdng \u0111\u1ec3 \u0111\u1ea3m b\u1ea3o t\u00ednh nh\u1ea5t qu\u00e1n v\u00e0 an to\u00e0n c\u1ee7a d\u1eef li\u1ec7u. C\u00f3 hai lo\u1ea1i th\u1ee9 t\u1ef1 th\u1ef1c hi\u1ec7n transaction ch\u00ednh:<\/span><\/p>\n<h3><b>Th\u1ee9 t\u1ef1 th\u1ef1c hi\u1ec7n tu\u1ea7n t\u1ef1 (Serial Schedule)<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Trong lo\u1ea1i th\u1ee9 t\u1ef1 n\u00e0y, c\u00e1c transaction \u0111\u01b0\u1ee3c th\u1ef1c hi\u1ec7n l\u1ea7n l\u01b0\u1ee3t, ngh\u0129a l\u00e0 ch\u1ec9 c\u00f3 m\u1ed9t transaction \u0111\u01b0\u1ee3c th\u1ef1c hi\u1ec7n t\u1ea1i m\u1ed9t th\u1eddi \u0111i\u1ec3m. Khi m\u1ed9t transaction k\u1ebft th\u00fac ho\u00e0n to\u00e0n, transaction ti\u1ebfp theo m\u1edbi b\u1eaft \u0111\u1ea7u.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u0110i\u1ec1u n\u00e0y \u0111\u1ea3m b\u1ea3o t\u00ednh nh\u1ea5t qu\u00e1n cho c\u01a1 s\u1edf d\u1eef li\u1ec7u v\u00ec c\u00e1c transaction kh\u00f4ng can thi\u1ec7p v\u00e0o nhau.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Tuy nhi\u00ean, vi\u1ec7c th\u1ef1c hi\u1ec7n tu\u1ea7n t\u1ef1 n\u00e0y l\u00e0m t\u0103ng th\u1eddi gian ch\u1edd c\u1ee7a c\u00e1c transaction v\u00e0 gi\u1ea3m hi\u1ec7u su\u1ea5t h\u1ec7 th\u1ed1ng (s\u1ed1 l\u01b0\u1ee3ng transaction \u0111\u01b0\u1ee3c x\u1eed l\u00fd trong m\u1ed9t kho\u1ea3ng th\u1eddi gian nh\u1ea5t \u0111\u1ecbnh b\u1ecb h\u1ea1n ch\u1ebf), \u0111i\u1ec1u n\u00e0y kh\u00f4ng ph\u00f9 h\u1ee3p v\u1edbi c\u00e1c h\u1ec7 th\u1ed1ng l\u1edbn.<\/span><\/p>\n<h3><b>Th\u1ee9 t\u1ef1 th\u1ef1c hi\u1ec7n kh\u00f4ng tu\u1ea7n t\u1ef1 (Non-Serial Schedule)<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">\u0110\u1ec3 t\u0103ng hi\u1ec7u qu\u1ea3 c\u1ee7a h\u1ec7 th\u1ed1ng, th\u1ee9 t\u1ef1 kh\u00f4ng tu\u1ea7n t\u1ef1 cho ph\u00e9p nhi\u1ec1u transaction c\u00f3 th\u1ec3 b\u1eaft \u0111\u1ea7u v\u00e0 th\u1ef1c thi song song, tr\u01b0\u1edbc khi transaction \u0111\u1ea7u ti\u00ean ho\u00e0n th\u00e0nh. \u0110i\u1ec1u n\u00e0y gi\u00fap gi\u1ea3m th\u1eddi gian ch\u1edd v\u00e0 t\u0103ng th\u00f4ng l\u01b0\u1ee3ng (throughput) c\u1ee7a h\u1ec7 th\u1ed1ng.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Tuy nhi\u00ean, n\u1ebfu kh\u00f4ng \u0111\u01b0\u1ee3c ki\u1ec3m so\u00e1t c\u1ea9n th\u1eadn, vi\u1ec7c th\u1ef1c thi kh\u00f4ng tu\u1ea7n t\u1ef1 c\u00f3 th\u1ec3 d\u1eabn \u0111\u1ebfn l\u1ed7i ho\u1eb7c t\u00ecnh tr\u1ea1ng kh\u00f4ng nh\u1ea5t qu\u00e1n trong c\u01a1 s\u1edf d\u1eef li\u1ec7u. \u0110\u1ec3 x\u1eed l\u00fd \u0111i\u1ec1u n\u00e0y, c\u00e1c thu\u1eadt to\u00e1n \u0111\u1eb7c bi\u1ec7t nh\u01b0 Two-Phase Locking, Timestamp Ordering, Serializable Schedule \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 \u0111\u1ea3m b\u1ea3o t\u00ednh nh\u1ea5t qu\u00e1n d\u1eef li\u1ec7u ngay c\u1ea3 khi c\u00e1c transaction th\u1ef1c hi\u1ec7n \u0111\u1ed3ng th\u1eddi.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Nh\u00ecn chung, trong m\u00f4i tr\u01b0\u1eddng x\u1eed l\u00fd \u0111\u1ed3ng th\u1eddi, vi\u1ec7c ch\u1ecdn lo\u1ea1i th\u1ee9 t\u1ef1 th\u1ef1c hi\u1ec7n ph\u1ee5 thu\u1ed9c v\u00e0o y\u00eau c\u1ea7u v\u1ec1 hi\u1ec7u su\u1ea5t v\u00e0 t\u00ednh nh\u1ea5t qu\u00e1n c\u1ee7a h\u1ec7 th\u1ed1ng. C\u00e1c giao d\u1ecbch tu\u1ea7n t\u1ef1 \u0111\u01b0\u1ee3c coi l\u00e0 chu\u1ea9n m\u1ef1c \u0111\u1ec3 so s\u00e1nh v\u00e0 \u0111\u00e1nh gi\u00e1, nh\u01b0ng giao d\u1ecbch kh\u00f4ng tu\u1ea7n t\u1ef1 n\u1ebfu \u0111\u01b0\u1ee3c qu\u1ea3n l\u00fd \u0111\u00fang c\u00e1ch, s\u1ebd gi\u00fap h\u1ec7 th\u1ed1ng ho\u1ea1t \u0111\u1ed9ng hi\u1ec7u qu\u1ea3 h\u01a1n m\u00e0 v\u1eabn duy tr\u00ec \u0111\u01b0\u1ee3c t\u00ednh nh\u1ea5t qu\u00e1n c\u1ee7a d\u1eef li\u1ec7u.<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Cac_thao_tac_co_ban_voi_transaction_trong_database\"><\/span><b>C\u00e1c thao t\u00e1c c\u01a1 b\u1ea3n v\u1edbi transaction trong database<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Trong qu\u00e1 tr\u00ecnh th\u1ef1c hi\u1ec7n transaction, c\u00f3 b\u1ed1n thao t\u00e1c c\u01a1 b\u1ea3n \u0111\u1ec3 truy c\u1eadp v\u00e0 thay \u0111\u1ed5i n\u1ed9i dung c\u1ee7a c\u01a1 s\u1edf d\u1eef li\u1ec7u. C\u00e1c thao t\u00e1c n\u00e0y \u0111\u1ea3m b\u1ea3o r\u1eb1ng d\u1eef li\u1ec7u \u0111\u01b0\u1ee3c x\u1eed l\u00fd m\u1ed9t c\u00e1ch an to\u00e0n v\u00e0 nh\u1ea5t qu\u00e1n<\/span><\/p>\n<h3><b>Read(X)<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Thao t\u00e1c \u0111\u1ecdc gi\u00e1 tr\u1ecb c\u1ee7a X t\u1eeb c\u01a1 s\u1edf d\u1eef li\u1ec7u v\u00e0 l\u01b0u tr\u1eef n\u00f3 trong b\u1ed9 nh\u1edb \u0111\u1ec7m (buffer) c\u1ee7a b\u1ed9 nh\u1edb ch\u00ednh \u0111\u1ec3 th\u1ef1c hi\u1ec7n c\u00e1c h\u00e0nh \u0111\u1ed9ng kh\u00e1c, ch\u1eb3ng h\u1ea1n nh\u01b0 hi\u1ec3n th\u1ecb gi\u00e1 tr\u1ecb n\u00e0y. Thao t\u00e1c \u0111\u1ecdc th\u01b0\u1eddng \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng khi ng\u01b0\u1eddi d\u00f9ng ch\u1ec9 mu\u1ed1n xem n\u1ed9i dung m\u00e0 kh\u00f4ng thay \u0111\u1ed5i n\u00f3.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5: Khi ng\u01b0\u1eddi d\u00f9ng ki\u1ec3m tra s\u1ed1 d\u01b0 t\u00e0i kho\u1ea3n ng\u00e2n h\u00e0ng c\u1ee7a m\u00ecnh, h\u1ec7 th\u1ed1ng s\u1ebd th\u1ef1c hi\u1ec7n thao t\u00e1c Read(X) \u0111\u1ec3 l\u1ea5y gi\u00e1 tr\u1ecb s\u1ed1 d\u01b0 t\u1eeb c\u01a1 s\u1edf d\u1eef li\u1ec7u v\u00e0 hi\u1ec3n th\u1ecb cho ng\u01b0\u1eddi d\u00f9ng. V\u00ed d\u1ee5 \u0111\u1ec3 l\u1ea5y th\u00f4ng tin s\u1ed1 d\u01b0 t\u1eeb t\u00e0i kho\u1ea3n c\u1ee7a m\u1ed9t ng\u01b0\u1eddi d\u00f9ng, ta s\u1eed d\u1ee5ng c\u00fa ph\u00e1p nh\u01b0 sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">SELECT balance FROM accounts WHERE account_id = '12345';<\/span><\/pre>\n<h3><b>Write(X)<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Thao t\u00e1c ghi gi\u00e1 tr\u1ecb t\u1eeb b\u1ed9 nh\u1edb \u0111\u1ec7m tr\u1edf l\u1ea1i c\u01a1 s\u1edf d\u1eef li\u1ec7u sau khi gi\u00e1 tr\u1ecb n\u00e0y \u0111\u00e3 \u0111\u01b0\u1ee3c thay \u0111\u1ed5i. \u0110\u1ec3 th\u1ef1c hi\u1ec7n thao t\u00e1c ghi, tr\u01b0\u1edbc ti\u00ean h\u1ec7 th\u1ed1ng s\u1ebd \u0111\u1ecdc gi\u00e1 tr\u1ecb X v\u00e0o b\u1ed9 nh\u1edb \u0111\u1ec7m th\u00f4ng qua thao t\u00e1c <\/span><b>Read(X)<\/b><span style=\"font-weight: 400;\">, sau \u0111\u00f3 th\u1ef1c hi\u1ec7n c\u00e1c thay \u0111\u1ed5i (nh\u01b0 t\u00ednh to\u00e1n) v\u00e0 cu\u1ed1i c\u00f9ng l\u01b0u l\u1ea1i k\u1ebft qu\u1ea3 v\u00e0o c\u01a1 s\u1edf d\u1eef li\u1ec7u.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5: Khi ng\u01b0\u1eddi d\u00f9ng r\u00fat ti\u1ec1n t\u1eeb t\u00e0i kho\u1ea3n, s\u1ed1 d\u01b0 c\u1ee7a t\u00e0i kho\u1ea3n s\u1ebd \u0111\u01b0\u1ee3c \u0111\u1ecdc t\u1eeb c\u01a1 s\u1edf d\u1eef li\u1ec7u, sau \u0111\u00f3 s\u1ed1 ti\u1ec1n r\u00fat s\u1ebd \u0111\u01b0\u1ee3c tr\u1eeb kh\u1ecfi s\u1ed1 d\u01b0 v\u00e0 cu\u1ed1i c\u00f9ng, gi\u00e1 tr\u1ecb s\u1ed1 d\u01b0 m\u1edbi s\u1ebd \u0111\u01b0\u1ee3c l\u01b0u l\u1ea1i trong c\u01a1 s\u1edf d\u1eef li\u1ec7u th\u00f4ng qua thao t\u00e1c Write(X). V\u00ed d\u1ee5 \u0111\u1ec3 c\u1eadp nh\u1eadt s\u1ed1 d\u01b0 t\u00e0i kho\u1ea3n sau khi ng\u01b0\u1eddi d\u00f9ng th\u1ef1c hi\u1ec7n r\u00fat ti\u1ec1n, ta s\u1eed d\u1ee5ng c\u00fa ph\u00e1p nh\u01b0 sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">UPDATE accounts SET balance = balance - 100 WHERE account_id = '12345';<\/span><\/pre>\n<h3><b>Insert(X)<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Insert \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 th\u00eam m\u1ed9t b\u1ea3n ghi m\u1edbi v\u00e0o b\u1ea3ng, gi\u00fap m\u1edf r\u1ed9ng d\u1eef li\u1ec7u trong c\u01a1 s\u1edf d\u1eef li\u1ec7u.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5: Khi ng\u01b0\u1eddi d\u00f9ng t\u1ea1o t\u00e0i kho\u1ea3n m\u1edbi, h\u1ec7 th\u1ed1ng s\u1ebd th\u1ef1c hi\u1ec7n thao t\u00e1c Insert \u0111\u1ec3 th\u00eam b\u1ea3n ghi m\u1edbi v\u1edbi th\u00f4ng tin t\u00e0i kho\u1ea3n v\u00e0o c\u01a1 s\u1edf d\u1eef li\u1ec7u.<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">INSERT INTO accounts (account_id, balance) VALUES ('12345', 500);<\/span><\/pre>\n<h3><b>Delete(X)<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Delete \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 lo\u1ea1i b\u1ecf d\u1eef li\u1ec7u kh\u00f4ng c\u00f2n c\u1ea7n thi\u1ebft ho\u1eb7c kh\u00f4ng h\u1ee3p l\u1ec7, \u0111\u1ea3m b\u1ea3o d\u1eef li\u1ec7u trong c\u01a1 s\u1edf d\u1eef li\u1ec7u lu\u00f4n ch\u00ednh x\u00e1c v\u00e0 kh\u00f4ng d\u01b0 th\u1eeba.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5: Khi ng\u01b0\u1eddi d\u00f9ng \u0111\u00f3ng t\u00e0i kho\u1ea3n, thao t\u00e1c Delete s\u1ebd \u0111\u01b0\u1ee3c th\u1ef1c thi \u0111\u1ec3 x\u00f3a b\u1ea3n ghi li\u00ean quan \u0111\u1ebfn t\u00e0i kho\u1ea3n \u0111\u00f3 kh\u1ecfi c\u01a1 s\u1edf d\u1eef li\u1ec7u v\u1edbi c\u00fa ph\u00e1p nh\u01b0 sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">DELETE FROM accounts WHERE account_id = '12345'; <\/span><\/pre>\n<h3><b>Commit<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Thao t\u00e1c n\u00e0y \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 x\u00e1c nh\u1eadn c\u00e1c thay \u0111\u1ed5i \u0111\u00e3 th\u1ef1c hi\u1ec7n b\u1edfi transaction. Khi m\u1ed9t transaction ho\u00e0n t\u1ea5t m\u00e0 kh\u00f4ng g\u1eb7p l\u1ed7i, thao t\u00e1c Commit s\u1ebd l\u01b0u v\u0129nh vi\u1ec5n c\u00e1c thay \u0111\u1ed5i v\u00e0o c\u01a1 s\u1edf d\u1eef li\u1ec7u. \u0110i\u1ec1u n\u00e0y gi\u00fap \u0111\u1ea3m b\u1ea3o t\u00ednh to\u00e0n v\u1eb9n c\u1ee7a d\u1eef li\u1ec7u, tr\u00e1nh s\u1ef1 kh\u00f4ng nh\u1ea5t qu\u00e1n do s\u1ef1 c\u1ed1 nh\u01b0 m\u1ea5t \u0111i\u1ec7n ho\u1eb7c h\u1ecfng ph\u1ea7n c\u1ee9ng.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5: Sau khi ng\u01b0\u1eddi d\u00f9ng th\u1ef1c hi\u1ec7n giao d\u1ecbch chuy\u1ec3n ti\u1ec1n, thao t\u00e1c Commit s\u1ebd \u0111\u01b0\u1ee3c th\u1ef1c hi\u1ec7n \u0111\u1ec3 \u0111\u1ea3m b\u1ea3o s\u1ed1 ti\u1ec1n \u0111\u00e3 \u0111\u01b0\u1ee3c tr\u1eeb t\u1eeb t\u00e0i kho\u1ea3n c\u1ee7a ng\u01b0\u1eddi g\u1eedi v\u00e0 c\u1ed9ng v\u00e0o t\u00e0i kho\u1ea3n c\u1ee7a ng\u01b0\u1eddi nh\u1eadn v\u1edbi c\u00fa ph\u00e1p sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">COMMIT;<\/span><\/pre>\n<h3><b>Rollback<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Thao t\u00e1c n\u00e0y \u0111\u01b0\u1ee3c th\u1ef1c hi\u1ec7n khi c\u00f3 s\u1ef1 c\u1ed1 x\u1ea3y ra trong qu\u00e1 tr\u00ecnh th\u1ef1c hi\u1ec7n transaction (v\u00ed d\u1ee5: m\u1ea5t \u0111i\u1ec7n, l\u1ed7i ph\u1ea7n c\u1ee9ng). Rollback s\u1ebd \u0111\u01b0a c\u01a1 s\u1edf d\u1eef li\u1ec7u tr\u1edf l\u1ea1i tr\u1ea1ng th\u00e1i tr\u01b0\u1edbc khi transaction b\u1eaft \u0111\u1ea7u, nh\u1eb1m \u0111\u1ea3m b\u1ea3o t\u00ednh an to\u00e0n v\u00e0 nh\u1ea5t qu\u00e1n cho d\u1eef li\u1ec7u.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5: N\u1ebfu h\u1ec7 th\u1ed1ng g\u1eb7p s\u1ef1 c\u1ed1 trong khi ng\u01b0\u1eddi d\u00f9ng \u0111ang th\u1ef1c hi\u1ec7n giao d\u1ecbch chuy\u1ec3n ti\u1ec1n, thao t\u00e1c Rollback s\u1ebd h\u1ee7y b\u1ecf m\u1ecdi thay \u0111\u1ed5i tr\u01b0\u1edbc \u0111\u00f3 v\u00e0 \u0111\u01b0a s\u1ed1 d\u01b0 t\u00e0i kho\u1ea3n tr\u1edf v\u1ec1 tr\u1ea1ng th\u00e1i ban \u0111\u1ea7u, nh\u01b0 th\u1ec3 giao d\u1ecbch ch\u01b0a bao gi\u1edd \u0111\u01b0\u1ee3c th\u1ef1c hi\u1ec7n v\u1edbi c\u00fa ph\u00e1p sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">ROLLBACK;<\/span><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Uu_diem_cua_transaction_trong_quan_ly_du_lieu\"><\/span><b>\u01afu \u0111i\u1ec3m c\u1ee7a transaction trong qu\u1ea3n l\u00fd d\u1eef li\u1ec7u<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Transaction trong c\u01a1 s\u1edf d\u1eef li\u1ec7u mang l\u1ea1i nhi\u1ec1u l\u1ee3i \u00edch quan tr\u1ecdng trong vi\u1ec7c qu\u1ea3n l\u00fd d\u1eef li\u1ec7u, \u0111\u1eb7c bi\u1ec7t l\u00e0 trong c\u00e1c h\u1ec7 th\u1ed1ng y\u00eau c\u1ea7u t\u00ednh to\u00e0n v\u1eb9n v\u00e0 b\u1ea3o m\u1eadt cao. D\u01b0\u1edbi \u0111\u00e2y l\u00e0 nh\u1eefng \u01b0u \u0111i\u1ec3m n\u1ed5i b\u1eadt:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>\u0110\u1ea3m b\u1ea3o t\u00ednh to\u00e0n v\u1eb9n c\u1ee7a d\u1eef li\u1ec7u<\/b><span style=\"font-weight: 400;\">: Transaction \u0111\u01b0\u1ee3c thi\u1ebft k\u1ebf tu\u00e2n th\u1ee7 c\u00e1c thu\u1ed9c t\u00ednh ACID, \u0111\u1ea3m b\u1ea3o r\u1eb1ng m\u1ecdi thao t\u00e1c tr\u00ean d\u1eef li\u1ec7u \u0111\u1ec1u ph\u1ea3i ho\u00e0n th\u00e0nh th\u00e0nh c\u00f4ng ho\u1eb7c ho\u00e0n to\u00e0n kh\u00f4ng th\u1ef1c hi\u1ec7n, tr\u00e1nh t\u00ecnh tr\u1ea1ng d\u1eef li\u1ec7u b\u1ecb thay \u0111\u1ed5i m\u1ed9t ph\u1ea7n. \u0110i\u1ec1u n\u00e0y r\u1ea5t quan tr\u1ecdng trong c\u00e1c \u1ee9ng d\u1ee5ng nh\u01b0 h\u1ec7 th\u1ed1ng ng\u00e2n h\u00e0ng, n\u01a1i m\u00e0 c\u00e1c giao d\u1ecbch t\u00e0i ch\u00ednh ph\u1ea3i \u0111\u1ea3m b\u1ea3o to\u00e0n b\u1ed9 ho\u1eb7c kh\u00f4ng thay \u0111\u1ed5i g\u00ec.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>X\u1eed l\u00fd l\u1ed7i hi\u1ec7u qu\u1ea3<\/b><span style=\"font-weight: 400;\">: Khi c\u00f3 l\u1ed7i x\u1ea3y ra trong qu\u00e1 tr\u00ecnh th\u1ef1c hi\u1ec7n transaction, c\u01a1 ch\u1ebf rollback cho ph\u00e9p ho\u00e0n t\u00e1c m\u1ecdi thay \u0111\u1ed5i \u0111\u00e3 th\u1ef1c hi\u1ec7n, gi\u00fap h\u1ec7 th\u1ed1ng tr\u1edf l\u1ea1i tr\u1ea1ng th\u00e1i an to\u00e0n tr\u01b0\u1edbc khi l\u1ed7i x\u1ea3y ra. \u0110i\u1ec1u n\u00e0y gi\u00fap \u0111\u1ea3m b\u1ea3o d\u1eef li\u1ec7u lu\u00f4n nh\u1ea5t qu\u00e1n v\u00e0 tr\u00e1nh t\u00ecnh tr\u1ea1ng kh\u00f4ng ch\u1eafc ch\u1eafn.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>C\u1ea3i thi\u1ec7n hi\u1ec7u su\u1ea5t v\u1edbi thao t\u00e1c \u0111\u1ed3ng th\u1eddi<\/b><span style=\"font-weight: 400;\">: Transaction cho ph\u00e9p nhi\u1ec1u thao t\u00e1c c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c th\u1ef1c hi\u1ec7n \u0111\u1ed3ng th\u1eddi m\u00e0 kh\u00f4ng l\u00e0m \u1ea3nh h\u01b0\u1edfng \u0111\u1ebfn t\u00ednh nh\u1ea5t qu\u00e1n c\u1ee7a d\u1eef li\u1ec7u. \u0110i\u1ec1u n\u00e0y gi\u00fap t\u0103ng hi\u1ec7u su\u1ea5t h\u1ec7 th\u1ed1ng, \u0111\u1eb7c bi\u1ec7t trong c\u00e1c m\u00f4i tr\u01b0\u1eddng c\u00f3 nhi\u1ec1u ng\u01b0\u1eddi d\u00f9ng ho\u1eb7c y\u00eau c\u1ea7u truy c\u1eadp d\u1eef li\u1ec7u li\u00ean t\u1ee5c nh\u01b0 c\u00e1c trang th\u01b0\u01a1ng m\u1ea1i \u0111i\u1ec7n t\u1eed, h\u1ec7 th\u1ed1ng \u0111\u1eb7t v\u00e9 m\u00e1y bay.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Gi\u1ea3m thi\u1ec3u sai s\u00f3t do l\u1ed7i ng\u01b0\u1eddi d\u00f9ng:<\/b><span style=\"font-weight: 400;\"> Transaction cho ph\u00e9p ki\u1ec3m tra l\u1ed7i v\u00e0 ho\u00e0n t\u00e1c c\u00e1c thao t\u00e1c sai l\u1ea7m b\u1eb1ng l\u1ec7nh rollback, gi\u00fap h\u1ec7 th\u1ed1ng c\u00f3 th\u1ec3 t\u1ef1 \u0111\u1ed9ng kh\u00f4i ph\u1ee5c tr\u1ea1ng th\u00e1i an to\u00e0n khi x\u1ea3y ra c\u00e1c thao t\u00e1c sai, t\u1eeb \u0111\u00f3 gi\u1ea3m thi\u1ec3u r\u1ee7i ro do l\u1ed7i ng\u01b0\u1eddi d\u00f9ng v\u00e0 \u0111\u1ea3m b\u1ea3o t\u00ednh nh\u1ea5t qu\u00e1n c\u1ee7a d\u1eef li\u1ec7u.\u00a0<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">V\u00ec v\u1eady transaction r\u1ea5t h\u1eefu \u00edch trong c\u00e1c h\u1ec7 th\u1ed1ng c\u1ea7n b\u1ea3o to\u00e0n t\u00ednh to\u00e0n v\u1eb9n c\u1ee7a d\u1eef li\u1ec7u nh\u01b0 h\u1ec7 th\u1ed1ng t\u00e0i ch\u00ednh, ng\u00e2n h\u00e0ng, qu\u1ea3n l\u00fd \u0111\u1eb7t ph\u00f2ng kh\u00e1ch s\u1ea1n, \u0111\u1eb7t v\u00e9 m\u00e1y bay v\u00e0 c\u00e1c trang th\u01b0\u01a1ng m\u1ea1i \u0111i\u1ec7n t\u1eed. C\u00e1c giao d\u1ecbch n\u00e0y c\u1ea7n \u0111\u1ea3m b\u1ea3o r\u1eb1ng m\u1ecdi thay \u0111\u1ed5i ph\u1ea3i \u0111\u01b0\u1ee3c th\u1ef1c hi\u1ec7n to\u00e0n di\u1ec7n, gi\u00fap h\u1ec7 th\u1ed1ng duy tr\u00ec t\u00ednh to\u00e0n v\u1eb9n v\u00e0 hi\u1ec7u su\u1ea5t, ngay c\u1ea3 trong nh\u1eefng t\u00ecnh hu\u1ed1ng ph\u1ee9c t\u1ea1p v\u00e0 c\u00f3 l\u1ed7i x\u1ea3y ra.<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Cau_hoi_thuong_gap_ve_transaction_trong_database\"><\/span><b>C\u00e2u h\u1ecfi th\u01b0\u1eddng g\u1eb7p v\u1ec1 transaction trong database<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><b>C\u00e1ch ph\u00e2n bi\u1ec7t transaction v\u00e0 query l\u00e0 g\u00ec?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\"><strong>Query<\/strong> l\u00e0 m\u1ed9t thao t\u00e1c \u0111\u01a1n l\u1ebb th\u1ef1c hi\u1ec7n c\u00e1c h\u00e0nh \u0111\u1ed9ng CRUD (Create, Read, Update, Delete) tr\u00ean d\u1eef li\u1ec7u trong m\u1ed9t b\u1ea3ng. V\u00ed d\u1ee5, m\u1ed9t query c\u00f3 th\u1ec3 l\u00e0 m\u1ed9t l\u1ec7nh \u0111\u1ec3 \u0111\u1ecdc d\u1eef li\u1ec7u t\u1eeb c\u01a1 s\u1edf d\u1eef li\u1ec7u ho\u1eb7c c\u1eadp nh\u1eadt m\u1ed9t gi\u00e1 tr\u1ecb c\u1ee5 th\u1ec3.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Ng\u01b0\u1ee3c l\u1ea1i, <strong>transaction<\/strong> l\u00e0 m\u1ed9t kh\u1ed1i h\u00e0nh \u0111\u1ed9ng bao g\u1ed3m m\u1ed9t ho\u1eb7c nhi\u1ec1u l\u1ec7nh, query v\u00e0 c\u00e1c thao t\u00e1c kh\u00e1c nhau \u0111\u01b0\u1ee3c th\u1ef1c hi\u1ec7n nh\u01b0 m\u1ed9t \u0111\u01a1n v\u1ecb kh\u00f4ng th\u1ec3 chia nh\u1ecf. Transaction \u0111\u1ea3m b\u1ea3o r\u1eb1ng t\u1ea5t c\u1ea3 c\u00e1c thao t\u00e1c b\u00ean trong n\u00f3 ph\u1ea3i ho\u00e0n th\u00e0nh th\u00e0nh c\u00f4ng ho\u1eb7c kh\u00f4ng \u0111\u01b0\u1ee3c th\u1ef1c hi\u1ec7n g\u00ec c\u1ea3, \u0111\u1ea3m b\u1ea3o t\u00ednh to\u00e0n v\u1eb9n c\u1ee7a d\u1eef li\u1ec7u.<\/span><\/p>\n<h3><b>NoSQL c\u00f3 h\u1ed7 tr\u1ee3 transaction kh\u00f4ng?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">M\u1ed9t s\u1ed1 c\u00f4ng ngh\u1ec7 NoSQL c\u0169ng h\u1ed7 tr\u1ee3 transaction m\u1eb7c d\u00f9 transaction th\u01b0\u1eddng g\u1eafn li\u1ec1n v\u1edbi c\u00e1c c\u01a1 s\u1edf d\u1eef li\u1ec7u quan h\u1ec7, nh\u01b0ng m\u1ed9t s\u1ed1 c\u01a1 s\u1edf d\u1eef li\u1ec7u NoSQL nh\u01b0 FoundationDB, MarkLogic v\u00e0 Oracle NoSQL c\u0169ng h\u1ed7 tr\u1ee3 c\u00e1c transaction \u0111\u1ec3 \u0111\u1ea3m b\u1ea3o t\u00ednh to\u00e0n v\u1eb9n c\u1ee7a d\u1eef li\u1ec7u.<\/span><\/p>\n<blockquote><p><em>\u0110\u1ecdc th\u00eam: <strong><a href=\"https:\/\/itviec.com\/blog\/nosql-la-gi\/\" target=\"_blank\" rel=\"noopener\">NoSQL l\u00e0 g\u00ec? V\u00ec sao g\u1ecdi NoSQL l\u00e0 b\u01b0\u1edbc ti\u1ebfn m\u1edbi trong qu\u1ea3n l\u00fd d\u1eef li\u1ec7u?<\/a><\/strong><\/em><\/p><\/blockquote>\n<h3><b>M\u1ed9t transaction trong c\u01a1 s\u1edf d\u1eef li\u1ec7u c\u00f3 th\u1ec3 \u1ea3nh h\u01b0\u1edfng \u0111\u1ebfn hi\u1ec7u su\u1ea5t kh\u00f4ng?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">M\u1eb7c d\u00f9 transaction \u0111\u1ea3m b\u1ea3o t\u00ednh nh\u1ea5t qu\u00e1n v\u00e0 b\u1ec1n v\u1eefng c\u1ee7a d\u1eef li\u1ec7u, nh\u01b0ng ch\u00fang c\u0169ng c\u00f3 th\u1ec3 l\u00e0m ch\u1eadm hi\u1ec7u su\u1ea5t h\u1ec7 th\u1ed1ng, \u0111\u1eb7c bi\u1ec7t l\u00e0 trong c\u00e1c h\u1ec7 th\u1ed1ng c\u00f3 kh\u1ed1i l\u01b0\u1ee3ng giao d\u1ecbch cao.<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Tong_ket_transaction_trong_database\"><\/span><b>T\u1ed5ng k\u1ebft transaction trong database<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Transaction trong database \u0111\u00f3ng vai tr\u00f2 thi\u1ebft y\u1ebfu trong vi\u1ec7c qu\u1ea3n l\u00fd d\u1eef li\u1ec7u, \u0111\u1ea3m b\u1ea3o r\u1eb1ng m\u1ecdi thao t\u00e1c \u0111\u01b0\u1ee3c th\u1ef1c hi\u1ec7n ch\u00ednh x\u00e1c v\u00e0 nh\u1ea5t qu\u00e1n. Nh\u1edd c\u00e1c t\u00ednh ch\u1ea5t ACID, transaction gi\u00fap duy tr\u00ec t\u00ednh to\u00e0n v\u1eb9n c\u1ee7a c\u01a1 s\u1edf d\u1eef li\u1ec7u ngay c\u1ea3 khi x\u1ea3y ra s\u1ef1 c\u1ed1. Transaction kh\u00f4ng ch\u1ec9 gi\u00fap t\u1ed1i \u01b0u h\u00f3a hi\u1ec7u su\u1ea5t h\u1ec7 th\u1ed1ng m\u00e0 c\u00f2n \u0111\u1ea3m b\u1ea3o s\u1ef1 an to\u00e0n v\u00e0 \u0111\u00e1ng tin c\u1eady c\u1ee7a d\u1eef li\u1ec7u trong c\u00e1c \u1ee9ng d\u1ee5ng th\u1ef1c t\u1ebf.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ITviec hy v\u1ecdng b\u00e0i vi\u1ebft tr\u00ean \u0111\u00e3 gi\u00fap b\u1ea1n c\u00f3 c\u00e1i nh\u00ecn chi ti\u1ebft h\u01a1n v\u1ec1 transaction v\u00e0 kh\u1ea3 n\u0103ng \u1ee9ng d\u1ee5ng trong c\u00e1c \u1ee9ng d\u1ee5ng th\u1ef1c t\u1ebf.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>MySQL, MariaDB, PostgreSQL, Oracle Database v\u00e0 Microsoft SQL Server l\u00e0 nh\u1eefng h\u1ec7 qu\u1ea3n tr\u1ecb c\u01a1 s\u1edf d\u1eef li\u1ec7u quan h\u1ec7 (RDBMS) ph\u1ed5 bi\u1ebfn nh\u1ea5t hi\u1ec7n nay. \u0110i\u1ec3m chung c\u1ee7a t\u1ea5t c\u1ea3 c\u00e1c h\u1ec7 th\u1ed1ng n\u00e0y l\u00e0 ch\u00fang \u0111\u1ec1u l\u00e0 c\u01a1 s\u1edf d\u1eef li\u1ec7u giao d\u1ecbch (transactional databases). \u0110i\u1ec1u n\u00e0y c\u00f3 ngh\u0129a l\u00e0 c\u00e1c h\u1ec7 th\u1ed1ng [&hellip;]<\/p>\n","protected":false},"author":209,"featured_media":81019,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_gspb_post_css":"","footnotes":""},"categories":[109],"tags":[],"class_list":["post-80857","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-chuyen-mon-it"],"blocksy_meta":[],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.8 (Yoast SEO v27.8) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Transaction trong database: C\u00e1c thao t\u00e1c c\u01a1 b\u1ea3n v\u1edbi transaction - ITviec Blog<\/title>\n<meta name=\"description\" content=\"H\u1ea7u h\u1ebft c\u00e1c RDBMS ph\u1ed5 bi\u1ebfn nh\u1ea5t hi\u1ec7n nay \u0111\u1ec1u l\u00e0 c\u01a1 s\u1edf d\u1eef li\u1ec7u giao d\u1ecbch. V\u1eady transaction trong database l\u00e0 g\u00ec v\u00e0 ho\u1ea1t \u0111\u1ed9ng nh\u01b0 th\u1ebf n\u00e0o?\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/itviec.com\/blog\/transaction-trong-database-la-gi\/\" \/>\n<meta property=\"og:locale\" content=\"vi_VN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Transaction trong database: C\u00e1c thao t\u00e1c c\u01a1 b\u1ea3n v\u1edbi transaction\" \/>\n<meta property=\"og:description\" content=\"MySQL, MariaDB, PostgreSQL, Oracle Database v\u00e0 Microsoft SQL Server l\u00e0 nh\u1eefng h\u1ec7 qu\u1ea3n tr\u1ecb c\u01a1 s\u1edf d\u1eef li\u1ec7u quan h\u1ec7 (RDBMS) ph\u1ed5 bi\u1ebfn nh\u1ea5t hi\u1ec7n nay. \u0110i\u1ec3m chung\" \/>\n<meta property=\"og:url\" content=\"https:\/\/itviec.com\/blog\/transaction-trong-database-la-gi\/\" \/>\n<meta property=\"og:site_name\" content=\"ITviec Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ITviec\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:02:42+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/10\/Transaction-trong-Database-vippro.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1500\" \/>\n\t<meta property=\"og:image:height\" content=\"790\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"M\u1ef9 Duy\u00ean\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@ITviec\" \/>\n<meta name=\"twitter:site\" content=\"@ITviec\" \/>\n<meta name=\"twitter:label1\" content=\"\u0110\u01b0\u1ee3c vi\u1ebft b\u1edfi\" \/>\n\t<meta name=\"twitter:data1\" content=\"M\u1ef9 Duy\u00ean\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u01af\u1edbc t\u00ednh th\u1eddi gian \u0111\u1ecdc\" \/>\n\t<meta name=\"twitter:data2\" content=\"19 ph\u00fat\" \/>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Transaction trong database: C\u00e1c thao t\u00e1c c\u01a1 b\u1ea3n v\u1edbi transaction - ITviec Blog","description":"H\u1ea7u h\u1ebft c\u00e1c RDBMS ph\u1ed5 bi\u1ebfn nh\u1ea5t hi\u1ec7n nay \u0111\u1ec1u l\u00e0 c\u01a1 s\u1edf d\u1eef li\u1ec7u giao d\u1ecbch. V\u1eady transaction trong database l\u00e0 g\u00ec v\u00e0 ho\u1ea1t \u0111\u1ed9ng nh\u01b0 th\u1ebf n\u00e0o?","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/itviec.com\/blog\/transaction-trong-database-la-gi\/","og_locale":"vi_VN","og_type":"article","og_title":"Transaction trong database: C\u00e1c thao t\u00e1c c\u01a1 b\u1ea3n v\u1edbi transaction","og_description":"MySQL, MariaDB, PostgreSQL, Oracle Database v\u00e0 Microsoft SQL Server l\u00e0 nh\u1eefng h\u1ec7 qu\u1ea3n tr\u1ecb c\u01a1 s\u1edf d\u1eef li\u1ec7u quan h\u1ec7 (RDBMS) ph\u1ed5 bi\u1ebfn nh\u1ea5t hi\u1ec7n nay. \u0110i\u1ec3m chung","og_url":"https:\/\/itviec.com\/blog\/transaction-trong-database-la-gi\/","og_site_name":"ITviec Blog","article_publisher":"https:\/\/www.facebook.com\/ITviec","article_published_time":"2024-11-01T09:02:42+00:00","og_image":[{"width":1500,"height":790,"url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/10\/Transaction-trong-Database-vippro.jpg","type":"image\/jpeg"}],"author":"M\u1ef9 Duy\u00ean","twitter_card":"summary_large_image","twitter_creator":"@ITviec","twitter_site":"@ITviec","twitter_misc":{"\u0110\u01b0\u1ee3c vi\u1ebft b\u1edfi":"M\u1ef9 Duy\u00ean","\u01af\u1edbc t\u00ednh th\u1eddi gian \u0111\u1ecdc":"19 ph\u00fat"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/itviec.com\/blog\/transaction-trong-database-la-gi\/#article","isPartOf":{"@id":"https:\/\/itviec.com\/blog\/transaction-trong-database-la-gi\/"},"author":{"name":"M\u1ef9 Duy\u00ean","@id":"https:\/\/itviec.com\/blog\/#\/schema\/person\/73733c0725c7e39e696a896bd1abe2d7"},"headline":"Transaction trong database: C\u00e1c thao t\u00e1c c\u01a1 b\u1ea3n v\u1edbi transaction","datePublished":"2024-11-01T09:02:42+00:00","mainEntityOfPage":{"@id":"https:\/\/itviec.com\/blog\/transaction-trong-database-la-gi\/"},"wordCount":4956,"publisher":{"@id":"https:\/\/itviec.com\/blog\/#organization"},"image":{"@id":"https:\/\/itviec.com\/blog\/transaction-trong-database-la-gi\/#primaryimage"},"thumbnailUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/10\/Transaction-trong-Database-vippro.jpg","articleSection":["Chuy\u00ean m\u00f4n IT"],"inLanguage":"vi"},{"@type":"WebPage","@id":"https:\/\/itviec.com\/blog\/transaction-trong-database-la-gi\/","url":"https:\/\/itviec.com\/blog\/transaction-trong-database-la-gi\/","name":"Transaction trong database: C\u00e1c thao t\u00e1c c\u01a1 b\u1ea3n v\u1edbi transaction - ITviec Blog","isPartOf":{"@id":"https:\/\/itviec.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/itviec.com\/blog\/transaction-trong-database-la-gi\/#primaryimage"},"image":{"@id":"https:\/\/itviec.com\/blog\/transaction-trong-database-la-gi\/#primaryimage"},"thumbnailUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/10\/Transaction-trong-Database-vippro.jpg","datePublished":"2024-11-01T09:02:42+00:00","description":"H\u1ea7u h\u1ebft c\u00e1c RDBMS ph\u1ed5 bi\u1ebfn nh\u1ea5t hi\u1ec7n nay \u0111\u1ec1u l\u00e0 c\u01a1 s\u1edf d\u1eef li\u1ec7u giao d\u1ecbch. V\u1eady transaction trong database l\u00e0 g\u00ec v\u00e0 ho\u1ea1t \u0111\u1ed9ng nh\u01b0 th\u1ebf n\u00e0o?","breadcrumb":{"@id":"https:\/\/itviec.com\/blog\/transaction-trong-database-la-gi\/#breadcrumb"},"inLanguage":"vi","potentialAction":[{"@type":"ReadAction","target":["https:\/\/itviec.com\/blog\/transaction-trong-database-la-gi\/"]}]},{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/itviec.com\/blog\/transaction-trong-database-la-gi\/#primaryimage","url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/10\/Transaction-trong-Database-vippro.jpg","contentUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/10\/Transaction-trong-Database-vippro.jpg","width":1500,"height":790,"caption":"Transaction trong Database - itviec blog"},{"@type":"BreadcrumbList","@id":"https:\/\/itviec.com\/blog\/transaction-trong-database-la-gi\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Chuy\u00ean m\u00f4n IT","item":"https:\/\/itviec.com\/blog\/chuyen-mon-it\/"},{"@type":"ListItem","position":2,"name":"Transaction trong database: C\u00e1c thao t\u00e1c c\u01a1 b\u1ea3n v\u1edbi transaction"}]},{"@type":"WebSite","@id":"https:\/\/itviec.com\/blog\/#website","url":"https:\/\/itviec.com\/blog\/","name":"ITviec Blog","description":"IT Jobs &amp; People in Vietnam","publisher":{"@id":"https:\/\/itviec.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/itviec.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"vi"},{"@type":"Organization","@id":"https:\/\/itviec.com\/blog\/#organization","name":"ITviec","url":"https:\/\/itviec.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/itviec.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2018\/12\/itviec-black-square-facebook.png","contentUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2018\/12\/itviec-black-square-facebook.png","width":1800,"height":1800,"caption":"ITviec"},"image":{"@id":"https:\/\/itviec.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/ITviec","https:\/\/x.com\/ITviec","https:\/\/www.linkedin.com\/company\/itviec","https:\/\/www.youtube.com\/channel\/UCYthAQ3bcGr57M_ag5gHDvQ"]},{"@type":"Person","@id":"https:\/\/itviec.com\/blog\/#\/schema\/person\/73733c0725c7e39e696a896bd1abe2d7","name":"M\u1ef9 Duy\u00ean","image":{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/03\/Author_Duyen-Tran-120x120.jpg","url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/03\/Author_Duyen-Tran-120x120.jpg","contentUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/03\/Author_Duyen-Tran-120x120.jpg","caption":"M\u1ef9 Duy\u00ean"},"url":"https:\/\/itviec.com\/blog\/author\/my-duyen\/"}]}},"_links":{"self":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts\/80857","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/users\/209"}],"replies":[{"embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/comments?post=80857"}],"version-history":[{"count":0,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts\/80857\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/media\/81019"}],"wp:attachment":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/media?parent=80857"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/categories?post=80857"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/tags?post=80857"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}