{"id":84495,"date":"2025-02-18T16:43:39","date_gmt":"2025-02-18T09:43:39","guid":{"rendered":"https:\/\/itviec.com\/blog\/?p=84495"},"modified":"2025-02-18T16:43:39","modified_gmt":"2025-02-18T09:43:39","slug":"cau-lenh-delete-trong-sql","status":"publish","type":"post","link":"https:\/\/itviec.com\/blog\/cau-lenh-delete-trong-sql\/","title":{"rendered":"C\u00e2u l\u1ec7nh DELETE trong SQL l\u00e0 g\u00ec? H\u01b0\u1edbng d\u1eabn s\u1eed d\u1ee5ng chi ti\u1ebft"},"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\/cau-lenh-delete-trong-sql\/#Cau_lenh_DELETE_trong_SQL_la_gi\" >C\u00e2u l\u1ec7nh DELETE trong SQL 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\/cau-lenh-delete-trong-sql\/#Cac_truong_hop_su_dung_cau_lenh_DELETE_trong_SQL\" >C\u00e1c tr\u01b0\u1eddng h\u1ee3p s\u1eed d\u1ee5ng c\u00e2u l\u1ec7nh DELETE trong SQL<\/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\/cau-lenh-delete-trong-sql\/#Mot_so_han_che_cua_cau_lenh_DELETE_trong_SQL\" >M\u1ed9t s\u1ed1 h\u1ea1n ch\u1ebf c\u1ee7a c\u00e2u l\u1ec7nh DELETE trong SQL<\/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\/cau-lenh-delete-trong-sql\/#Cau_hoi_thuong_gap_ve_cau_lenh_DELETE_trong_SQL\" >C\u00e2u h\u1ecfi th\u01b0\u1eddng g\u1eb7p v\u1ec1 c\u00e2u l\u1ec7nh DELETE trong SQL<\/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\/cau-lenh-delete-trong-sql\/#Tong_ket_cau_lenh_DELETE_trong_SQL\" >T\u1ed5ng k\u1ebft c\u00e2u l\u1ec7nh DELETE trong SQL<\/a><\/li><\/ul><\/nav><\/div>\n<p><em><strong>C\u00e2u l\u1ec7nh DELETE trong SQL \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 x\u00f3a d\u1eef li\u1ec7u kh\u00f4ng c\u1ea7n thi\u1ebft t\u1eeb c\u01a1 s\u1edf d\u1eef li\u1ec7u. Hi\u1ec3u c\u00e1ch ho\u1ea1t \u0111\u1ed9ng v\u00e0 \u00e1p d\u1ee5ng l\u1ec7nh DELETE gi\u00fap b\u1ea1n qu\u1ea3n l\u00fd d\u1eef li\u1ec7u hi\u1ec7u qu\u1ea3, tr\u00e1nh r\u1ee7i ro m\u1ea5t d\u1eef li\u1ec7u kh\u00f4ng mong mu\u1ed1n.<\/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;\">T\u1ed5ng quan v\u1ec1 c\u00e2u l\u1ec7nh DELETE trong SQL<\/span><span style=\"font-weight: 400;\">\u00a0v\u00e0 c\u00fa ph\u00e1p<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">\u1ee8ng d\u1ee5ng c\u1ee7a c\u00e2u l\u1ec7nh DELETE trong SQL<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">M\u1ed9t s\u1ed1 h\u1ea1n ch\u1ebf c\u1ee7a c\u00e2u l\u1ec7nh DELETE trong SQL<\/span><\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Cau_lenh_DELETE_trong_SQL_la_gi\"><\/span>C\u00e2u l\u1ec7nh DELETE trong SQL l\u00e0 g\u00ec?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">C\u00e2u l\u1ec7nh DELETE trong SQL l\u00e0 m\u1ed9t c\u00f4ng c\u1ee5 quan tr\u1ecdng trong vi\u1ec7c qu\u1ea3n l\u00fd v\u00e0 l\u00e0m s\u1ea1ch d\u1eef li\u1ec7u c\u1ee7a SQL, cho ph\u00e9p lo\u1ea1i b\u1ecf c\u00e1c b\u1ea3n ghi kh\u00f4ng c\u00f2n c\u1ea7n thi\u1ebft d\u1ef1a tr\u00ean c\u00e1c \u0111i\u1ec1u ki\u1ec7n c\u1ee5 th\u1ec3 m\u00e0 kh\u00f4ng l\u00e0m \u1ea3nh h\u01b0\u1edfng \u0111\u1ebfn c\u00e1c th\u00e0nh ph\u1ea7n kh\u00e1c c\u1ee7a b\u1ea3ng (c\u1ea5u tr\u00fac, ch\u1ec9 m\u1ee5c, r\u00e0ng bu\u1ed9c).<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Tuy nhi\u00ean, vi\u1ec7c s\u1eed d\u1ee5ng l\u1ec7nh <\/span><span style=\"font-weight: 400;\">DELETE<\/span><span style=\"font-weight: 400;\"> c\u1ea7n \u0111\u01b0\u1ee3c th\u1ef1c hi\u1ec7n m\u1ed9t c\u00e1ch c\u1ea9n th\u1eadn v\u00ec khi d\u1eef li\u1ec7u \u0111\u00e3 b\u1ecb x\u00f3a ta kh\u00f4ng th\u1ec3 ho\u00e0n t\u00e1c (revoke) n\u1ebfu l\u1ec7nh kh\u00f4ng \u0111\u01b0\u1ee3c th\u1ef1c hi\u1ec7n trong m\u1ed9t giao d\u1ecbch (transaction) h\u1ed7 tr\u1ee3 rollback.<\/span><\/p>\n<p><b>C\u00fa ph\u00e1p t\u1ed5ng qu\u00e1t:<\/b><\/p>\n<pre><span style=\"font-weight: 400;\">DELETE FROM table_name<\/span>\r\n\r\n<span style=\"font-weight: 400;\">WHERE condition;<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Trong \u0111\u00f3:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">table_name<\/span><span style=\"font-weight: 400;\">: T\u00ean b\u1ea3ng ch\u1ee9a c\u00e1c b\u1ea3n ghi c\u1ea7n x\u00f3a.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">condition<\/span><span style=\"font-weight: 400;\">: \u0110i\u1ec1u ki\u1ec7n l\u1ecdc c\u00e1c b\u1ea3n ghi c\u1ea7n x\u00f3a. Ch\u1ec9 nh\u1eefng b\u1ea3n ghi th\u1ecfa m\u00e3n \u0111i\u1ec1u ki\u1ec7n n\u00e0y m\u1edbi b\u1ecb x\u00f3a. N\u1ebfu kh\u00f4ng cung c\u1ea5p \u0111i\u1ec1u ki\u1ec7n (b\u1ecf <\/span><span style=\"font-weight: 400;\">WHERE<\/span><span style=\"font-weight: 400;\">), to\u00e0n b\u1ed9 d\u1eef li\u1ec7u trong b\u1ea3ng s\u1ebd b\u1ecb x\u00f3a.<\/span><\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Cac_truong_hop_su_dung_cau_lenh_DELETE_trong_SQL\"><\/span><b>C\u00e1c tr\u01b0\u1eddng h\u1ee3p s\u1eed d\u1ee5ng c\u00e2u l\u1ec7nh DELETE trong SQL<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Gi\u1ea3 s\u1eed ta c\u00f3 c\u00e1c b\u1ea3ng:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">B\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">employees<\/span><\/i><span style=\"font-weight: 400;\"> ch\u1ee9a th\u00f4ng tin c\u1ee7a nh\u00e2n vi\u00ean nh\u01b0 id, t\u00ean, ph\u00f2ng ban, l\u01b0\u01a1ng v\u00e0 tr\u1ea1ng th\u00e1i nh\u01b0 sau:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>employee_id<\/b><\/td>\n<td><b>name<\/b><\/td>\n<td><b>department_id<\/b><\/td>\n<td><b>salary<\/b><\/td>\n<td><b>status<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">1<\/span><\/td>\n<td><span style=\"font-weight: 400;\">John Doe<\/span><\/td>\n<td><span style=\"font-weight: 400;\">1<\/span><\/td>\n<td><span style=\"font-weight: 400;\">50000.00<\/span><\/td>\n<td><span style=\"font-weight: 400;\">active<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">2<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Jane Smith<\/span><\/td>\n<td><span style=\"font-weight: 400;\">2<\/span><\/td>\n<td><span style=\"font-weight: 400;\">60000.00<\/span><\/td>\n<td><span style=\"font-weight: 400;\">active<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">3<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Alice Johnson<\/span><\/td>\n<td><span style=\"font-weight: 400;\">3<\/span><\/td>\n<td><span style=\"font-weight: 400;\">55000.00<\/span><\/td>\n<td><span style=\"font-weight: 400;\">inactive<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">4<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Bob Brown<\/span><\/td>\n<td><span style=\"font-weight: 400;\">1<\/span><\/td>\n<td><span style=\"font-weight: 400;\">48000.00<\/span><\/td>\n<td><span style=\"font-weight: 400;\">active<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">5<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Emma Davis<\/span><\/td>\n<td><span style=\"font-weight: 400;\">3<\/span><\/td>\n<td><span style=\"font-weight: 400;\">62000.00<\/span><\/td>\n<td><span style=\"font-weight: 400;\">terminated<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">6<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Mike Wilson<\/span><\/td>\n<td><span style=\"font-weight: 400;\">3<\/span><\/td>\n<td><span style=\"font-weight: 400;\">51000.00<\/span><\/td>\n<td><span style=\"font-weight: 400;\">inactive<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\">B\u1ea3ng departments ch\u1ee9a th\u00f4ng tin v\u1ec1 c\u00e1c ph\u00f2ng ban g\u1ed3m id v\u00e0 t\u00ean ph\u00f2ng:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>department_id<\/b><\/td>\n<td><b>department_name<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">1<\/span><\/td>\n<td><span style=\"font-weight: 400;\">HR<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">2<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Finance<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">3<\/span><\/td>\n<td><span style=\"font-weight: 400;\">IT<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\">B\u1ea1n c\u00f3 th\u1ec3 th\u1ef1c h\u00e0nh t\u1ea1o b\u1ea3ng tr\u00ean tr\u00ean SQL Server v\u1edbi c\u00fa ph\u00e1p sau:\u00a0<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">-- t\u1ea1o b\u1ea3ng employees<\/span>\r\n\r\n<span style=\"font-weight: 400;\">CREATE TABLE employees (<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0employee_id INT PRIMARY KEY,<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0name NVARCHAR(50),<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0department NVARCHAR(50),<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0salary DECIMAL(10, 2),<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0status NVARCHAR(20)<\/span>\r\n<span style=\"font-weight: 400;\">);<\/span>\r\n\r\n<span style=\"font-weight: 400;\">-- th\u00eam d\u1eef li\u1ec7u v\u00e0o b\u1ea3ng employees<\/span>\r\n\r\n<span style=\"font-weight: 400;\">INSERT INTO employees (employee_id, name, department, salary, status) VALUES<\/span>\r\n<span style=\"font-weight: 400;\">(1, 'John Doe', 'HR', 50000.00, 'active'),<\/span>\r\n<span style=\"font-weight: 400;\">(2, 'Jane Smith', 'Finance', 60000.00, 'active'),<\/span>\r\n<span style=\"font-weight: 400;\">(3, 'Alice Johnson', 'IT', 55000.00, 'inactive'),<\/span>\r\n<span style=\"font-weight: 400;\">(4, 'Bob Brown', 'HR', 48000.00, 'active'),<\/span>\r\n<span style=\"font-weight: 400;\">(5, 'Emma Davis', 'IT', 62000.00, 'terminated');<\/span>\r\n\r\n<span style=\"font-weight: 400;\">-- t\u1ea1o b\u1ea3ng departments<\/span>\r\n\r\n<span style=\"font-weight: 400;\">CREATE TABLE departments (<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0department_id INT PRIMARY KEY,<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0department_name NVARCHAR(50)<\/span>\r\n<span style=\"font-weight: 400;\">);<\/span>\r\n\r\n<span style=\"font-weight: 400;\">-- th\u00eam d\u1eef li\u1ec7u v\u00e0o b\u1ea3ng departments\r\n<\/span>\r\n<span style=\"font-weight: 400;\">INSERT INTO departments (department_id, department_name) VALUES<\/span>\r\n<span style=\"font-weight: 400;\">(1, 'HR'),<\/span>\r\n<span style=\"font-weight: 400;\">(2, 'Finance'),<\/span>\r\n<span style=\"font-weight: 400;\">(3, 'IT');<\/span><\/pre>\n<h3><b>X\u00f3a m\u1ed9t b\u1ea3n ghi c\u1ee5 th\u1ec3<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Ta c\u00f3 th\u1ec3 x\u00f3a m\u1ed9t b\u1ea3n ghi c\u1ee5 th\u1ec3 b\u1eb1ng c\u00e1ch k\u1ebft h\u1ee3p v\u1edbi \u0111i\u1ec1u ki\u1ec7n WHERE. V\u00ed d\u1ee5 \u0111\u1ec3 xo\u00e1 b\u1ea3n ghi c\u1ee7a nh\u00e2n vi\u00ean c\u00f3 <\/span><span style=\"font-weight: 400;\">employee_id = 5<\/span><span style=\"font-weight: 400;\"> ta s\u1eed d\u1ee5ng c\u00fa ph\u00e1p sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">DELETE FROM employees<\/span>\r\n\r\n<span style=\"font-weight: 400;\">WHERE employee_id = 5;<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Gi\u1ea3i th\u00edch: L\u1ec7nh tr\u00ean t\u00ecm v\u00e0 x\u00f3a b\u1ea3n ghi c\u00f3 <\/span><span style=\"font-weight: 400;\">employee_id = 5<\/span><span style=\"font-weight: 400;\">. D\u1eef li\u1ec7u c\u1ee7a Emma Davis s\u1ebd b\u1ecb lo\u1ea1i b\u1ecf.<\/span><\/p>\n<h3><b>X\u00f3a nhi\u1ec1u b\u1ea3n ghi d\u1ef1a tr\u00ean \u0111i\u1ec1u ki\u1ec7n<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 \u0111\u1ec3 x\u00f3a t\u1ea5t c\u1ea3 nh\u00e2n vi\u00ean c\u00f3 tr\u1ea1ng th\u00e1i l\u00e0 <\/span><i><span style=\"font-weight: 400;\">inactive<\/span><\/i><span style=\"font-weight: 400;\"> ta s\u1eed d\u1ee5ng c\u00fa ph\u00e1p:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">DELETE FROM employees<\/span>\r\n\r\n<span style=\"font-weight: 400;\">WHERE status = 'inactive';<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">B\u1ea3ng employees s\u1ebd tr\u1edf th\u00e0nh:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>employee_id<\/b><\/td>\n<td><b>name<\/b><\/td>\n<td><b>department_id<\/b><\/td>\n<td><b>salary<\/b><\/td>\n<td><b>status<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">1<\/span><\/td>\n<td><span style=\"font-weight: 400;\">John Doe<\/span><\/td>\n<td><span style=\"font-weight: 400;\">1<\/span><\/td>\n<td><span style=\"font-weight: 400;\">50000.00<\/span><\/td>\n<td><span style=\"font-weight: 400;\">active<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">2<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Jane Smith<\/span><\/td>\n<td><span style=\"font-weight: 400;\">2<\/span><\/td>\n<td><span style=\"font-weight: 400;\">60000.00<\/span><\/td>\n<td><span style=\"font-weight: 400;\">active<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">4<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Bob Brown<\/span><\/td>\n<td><span style=\"font-weight: 400;\">1<\/span><\/td>\n<td><span style=\"font-weight: 400;\">48000.00<\/span><\/td>\n<td><span style=\"font-weight: 400;\">active<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\">Gi\u1ea3i th\u00edch: B\u1ea3n ghi c\u1ee7a Alice Johnson v\u00e0 Mike Wilson s\u1ebd b\u1ecb x\u00f3a v\u00ec c\u00f3 tr\u1ea1ng th\u00e1i l\u00e0 \u201cinactive\u201d.<\/span><\/p>\n<h3><b>X\u00f3a d\u1ef1a tr\u00ean nhi\u1ec1u \u0111i\u1ec1u ki\u1ec7n<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Ngo\u00e0i ra, ta c\u00f3 th\u1ec3 k\u1ebft h\u1ee3p nhi\u1ec1u \u0111i\u1ec1u ki\u1ec7n trong <\/span><span style=\"font-weight: 400;\">WHERE<\/span><span style=\"font-weight: 400;\"> \u0111\u1ec3 ch\u1ec9 x\u00f3a c\u00e1c b\u1ea3n ghi th\u1ecfa m\u00e3n \u0111\u1ed3ng th\u1eddi nhi\u1ec1u \u0111i\u1ec1u ki\u1ec7n. V\u00ed d\u1ee5, x\u00f3a t\u1ea5t c\u1ea3 nh\u00e2n vi\u00ean thu\u1ed9c ph\u00f2ng ban &#8220;IT&#8221; v\u00e0 c\u00f3 tr\u1ea1ng th\u00e1i &#8220;terminated&#8221; v\u1edbi c\u00fa ph\u00e1p nh\u01b0 sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">DELETE FROM employees<\/span>\r\n\r\n<span style=\"font-weight: 400;\">WHERE department_id = 3 AND status = 'terminated';<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">B\u1ea3ng employees s\u1ebd tr\u1edf th\u00e0nh:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>employee_id<\/b><\/td>\n<td><b>name<\/b><\/td>\n<td><b>department_id<\/b><\/td>\n<td><b>salary<\/b><\/td>\n<td><b>status<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">1<\/span><\/td>\n<td><span style=\"font-weight: 400;\">John Doe<\/span><\/td>\n<td><span style=\"font-weight: 400;\">1<\/span><\/td>\n<td><span style=\"font-weight: 400;\">50000.00<\/span><\/td>\n<td><span style=\"font-weight: 400;\">active<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">2<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Jane Smith<\/span><\/td>\n<td><span style=\"font-weight: 400;\">2<\/span><\/td>\n<td><span style=\"font-weight: 400;\">60000.00<\/span><\/td>\n<td><span style=\"font-weight: 400;\">active<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">3<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Alice Johnson<\/span><\/td>\n<td><span style=\"font-weight: 400;\">3<\/span><\/td>\n<td><span style=\"font-weight: 400;\">55000.00<\/span><\/td>\n<td><span style=\"font-weight: 400;\">inactive<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">4<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Bob Brown<\/span><\/td>\n<td><span style=\"font-weight: 400;\">1<\/span><\/td>\n<td><span style=\"font-weight: 400;\">48000.00<\/span><\/td>\n<td><span style=\"font-weight: 400;\">active<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">6<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Mike Wilson<\/span><\/td>\n<td><span style=\"font-weight: 400;\">3<\/span><\/td>\n<td><span style=\"font-weight: 400;\">51000.00<\/span><\/td>\n<td><span style=\"font-weight: 400;\">inactive<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\">Gi\u1ea3i th\u00edch: B\u1ea3n ghi c\u1ee7a Emma Davis b\u1ecb x\u00f3a v\u00ec thu\u1ed9c ph\u00f2ng ban IT v\u00e0 c\u00f3 tr\u1ea1ng th\u00e1i &#8220;terminated&#8221;.<\/span><\/p>\n<h3><b>X\u00f3a to\u00e0n b\u1ed9 d\u1eef li\u1ec7u trong b\u1ea3ng<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 \u0111\u1ec3 x\u00f3a to\u00e0n b\u1ed9 d\u1eef li\u1ec7u trong b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">employees<\/span><\/i><span style=\"font-weight: 400;\">, nh\u01b0ng gi\u1eef nguy\u00ean c\u1ea5u tr\u00fac b\u1ea3ng ta s\u1eed d\u1ee5ng c\u00fa ph\u00e1p:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">DELETE FROM employees;<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Gi\u1ea3i th\u00edch: Khi kh\u00f4ng s\u1eed d\u1ee5ng \u0111i\u1ec1u ki\u1ec7n <\/span><span style=\"font-weight: 400;\">WHERE<\/span><span style=\"font-weight: 400;\">, c\u00fa ph\u00e1p tr\u00ean s\u1ebd x\u00f3a t\u1ea5t c\u1ea3 d\u1eef li\u1ec7u trong b\u1ea3ng nh\u01b0ng kh\u00f4ng \u1ea3nh h\u01b0\u1edfng \u0111\u1ebfn c\u1ea5u tr\u00fac b\u1ea3ng.<\/span><\/p>\n<h3><b>X\u00f3a d\u1eef li\u1ec7u li\u00ean quan gi\u1eefa c\u00e1c b\u1ea3ng<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Gi\u1ea3 s\u1eed ta mu\u1ed1n x\u00f3a t\u1ea5t c\u1ea3 nh\u00e2n vi\u00ean thu\u1ed9c ph\u00f2ng ban &#8220;HR&#8221;. V\u00ec <\/span><i><span style=\"font-weight: 400;\">department_id<\/span><\/i><span style=\"font-weight: 400;\"> l\u00e0 kh\u00f3a ngo\u1ea1i li\u00ean k\u1ebft gi\u1eefa hai b\u1ea3ng, ta s\u1eed d\u1ee5ng <\/span><span style=\"font-weight: 400;\">JOIN<\/span><span style=\"font-weight: 400;\"> \u0111\u1ec3 x\u00e1c \u0111\u1ecbnh c\u00e1c nh\u00e2n vi\u00ean c\u1ea7n x\u00f3a tr\u01b0\u1edbc khi th\u1ef1c hi\u1ec7n l\u1ec7nh <\/span><span style=\"font-weight: 400;\">DELETE<\/span><span style=\"font-weight: 400;\"> v\u1edbi c\u00fa ph\u00e1p sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">DELETE e<\/span>\r\n\r\n<span style=\"font-weight: 400;\">FROM employees e<\/span>\r\n\r\n<span style=\"font-weight: 400;\">JOIN departments d ON e.department_id = d.department_id<\/span>\r\n\r\n<span style=\"font-weight: 400;\">WHERE d.department_name = 'HR';<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">B\u1ea3ng employees s\u1ebd tr\u1edf th\u00e0nh:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>employee_id<\/b><\/td>\n<td><b>name<\/b><\/td>\n<td><b>department_id<\/b><\/td>\n<td><b>salary<\/b><\/td>\n<td><b>status<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">2<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Jane Smith<\/span><\/td>\n<td><span style=\"font-weight: 400;\">2<\/span><\/td>\n<td><span style=\"font-weight: 400;\">60000.00<\/span><\/td>\n<td><span style=\"font-weight: 400;\">active<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">3<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Alice Johnson<\/span><\/td>\n<td><span style=\"font-weight: 400;\">3<\/span><\/td>\n<td><span style=\"font-weight: 400;\">55000.00<\/span><\/td>\n<td><span style=\"font-weight: 400;\">inactive<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">5<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Emma Davis<\/span><\/td>\n<td><span style=\"font-weight: 400;\">3<\/span><\/td>\n<td><span style=\"font-weight: 400;\">62000.00<\/span><\/td>\n<td><span style=\"font-weight: 400;\">terminated<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">6<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Mike Wilson<\/span><\/td>\n<td><span style=\"font-weight: 400;\">3<\/span><\/td>\n<td><span style=\"font-weight: 400;\">51000.00<\/span><\/td>\n<td><span style=\"font-weight: 400;\">inactive<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\">Gi\u1ea3i th\u00edch: T\u1ea5t c\u1ea3 nh\u00e2n vi\u00ean thu\u1ed9c ph\u00f2ng ban <\/span><i><span style=\"font-weight: 400;\">HR<\/span><\/i><span style=\"font-weight: 400;\"> (John Doe v\u00e0 Bob Brown) s\u1ebd b\u1ecb x\u00f3a.<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Mot_so_han_che_cua_cau_lenh_DELETE_trong_SQL\"><\/span><b>M\u1ed9t s\u1ed1 h\u1ea1n ch\u1ebf c\u1ee7a c\u00e2u l\u1ec7nh DELETE trong SQL<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><b>Hi\u1ec7u su\u1ea5t th\u1ea5p khi x\u00f3a s\u1ed1 l\u01b0\u1ee3ng l\u1edbn d\u1eef li\u1ec7u<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">L\u1ec7nh <\/span><span style=\"font-weight: 400;\">DELETE<\/span><span style=\"font-weight: 400;\"> x\u1eed l\u00fd t\u1eebng b\u1ea3n ghi m\u1ed9t v\u00e0 ghi l\u1ea1i c\u00e1c thay \u0111\u1ed5i trong nh\u1eadt k\u00fd giao d\u1ecbch (transaction log), khi\u1ebfn n\u00f3 ch\u1eadm h\u01a1n so v\u1edbi c\u00e1c l\u1ec7nh nh\u01b0 <\/span><span style=\"font-weight: 400;\">TRUNCATE<\/span><span style=\"font-weight: 400;\"> khi c\u1ea7n x\u00f3a to\u00e0n b\u1ed9 b\u1ea3ng ho\u1eb7c m\u1ed9t l\u01b0\u1ee3ng l\u1edbn d\u1eef li\u1ec7u.<\/span><\/p>\n<h3><b>Kh\u00f4ng th\u1ec3 ho\u00e0n t\u00e1c n\u1ebfu kh\u00f4ng s\u1eed d\u1ee5ng giao d\u1ecbch<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Sau khi l\u1ec7nh <\/span><span style=\"font-weight: 400;\">DELETE<\/span><span style=\"font-weight: 400;\"> \u0111\u01b0\u1ee3c th\u1ef1c thi v\u00e0 cam k\u1ebft (commit), d\u1eef li\u1ec7u b\u1ecb x\u00f3a s\u1ebd kh\u00f4ng th\u1ec3 kh\u00f4i ph\u1ee5c, tr\u1eeb khi b\u1ea1n c\u00f3 b\u1ea3n sao l\u01b0u. V\u00ec v\u1eady ph\u1ea3i c\u1ea9n th\u1eadn khi s\u1eed d\u1ee5ng, \u0111\u1eb7c bi\u1ec7t khi x\u00f3a d\u1eef li\u1ec7u nh\u1ea1y c\u1ea3m.<\/span><\/p>\n<h3><b>Kh\u00f4ng gi\u1ea3i ph\u00f3ng kh\u00f4ng gian b\u1ed9 nh\u1edb ngay l\u1eadp t\u1ee9c<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">L\u1ec7nh <\/span><span style=\"font-weight: 400;\">DELETE<\/span><span style=\"font-weight: 400;\"> kh\u00f4ng gi\u1ea3i ph\u00f3ng kh\u00f4ng gian b\u1ed9 nh\u1edb v\u1eadt l\u00fd trong c\u01a1 s\u1edf d\u1eef li\u1ec7u, v\u00ec v\u1eady b\u1ea3ng c\u00f3 th\u1ec3 v\u1eabn chi\u1ebfm dung l\u01b0\u1ee3ng l\u1edbn ngay c\u1ea3 khi d\u1eef li\u1ec7u \u0111\u00e3 b\u1ecb x\u00f3a.<\/span><\/p>\n<h3><strong>Ph\u1ee5 thu\u1ed9c v\u00e0o r\u00e0ng bu\u1ed9c kh\u00f3a ngo\u1ea1i<\/strong><\/h3>\n<p><span style=\"font-weight: 400;\">N\u1ebfu b\u1ea3ng c\u00f3 c\u00e1c r\u00e0ng bu\u1ed9c kh\u00f3a ngo\u1ea1i, vi\u1ec7c x\u00f3a d\u1eef li\u1ec7u li\u00ean quan c\u00f3 th\u1ec3 g\u00e2y l\u1ed7i ho\u1eb7c y\u00eau c\u1ea7u x\u00f3a d\u1eef li\u1ec7u trong c\u00e1c b\u1ea3ng kh\u00e1c tr\u01b0\u1edbc, khi\u1ebfn thao t\u00e1c DELETE tr\u1edf n\u00ean ph\u1ee9c t\u1ea1p h\u01a1n.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Ngo\u00e0i ra, c\u00f2n c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng t\u00f9y ch\u1ecdn <\/span><span style=\"font-weight: 400;\">ON DELETE CASCADE<\/span><span style=\"font-weight: 400;\"> khi khai b\u00e1o kh\u00f3a ngo\u1ea1i \u0111\u1ec3 t\u1ef1 \u0111\u1ed9ng x\u00f3a c\u00e1c b\u1ea3n ghi li\u00ean quan. Khi m\u1ed9t b\u1ea3n ghi trong b\u1ea3ng cha b\u1ecb x\u00f3a, t\u1ea5t c\u1ea3 c\u00e1c b\u1ea3n ghi trong b\u1ea3ng con tham chi\u1ebfu \u0111\u1ebfn n\u00f3 c\u0169ng s\u1ebd b\u1ecb x\u00f3a theo, gi\u00fap tr\u00e1nh l\u1ed7i r\u00e0ng bu\u1ed9c d\u1eef li\u1ec7u v\u00e0 gi\u1ea3m b\u1edbt c\u00f4ng vi\u1ec7c x\u00f3a th\u1ee7 c\u00f4ng.<\/span><\/p>\n<h3><b>Kh\u00f4ng ph\u00f9 h\u1ee3p cho c\u00e1c t\u00e1c v\u1ee5 x\u00f3a to\u00e0n b\u1ed9 d\u1eef li\u1ec7u th\u01b0\u1eddng xuy\u00ean<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Trong c\u00e1c tr\u01b0\u1eddng h\u1ee3p c\u1ea7n l\u00e0m s\u1ea1ch b\u1ea3ng th\u01b0\u1eddng xuy\u00ean (v\u00ed d\u1ee5 nh\u01b0 b\u1ea3ng t\u1ea1m), l\u1ec7nh <\/span><span style=\"font-weight: 400;\">DELETE<\/span><span style=\"font-weight: 400;\"> kh\u00f4ng ph\u1ea3i l\u00e0 l\u1ef1a ch\u1ecdn t\u1ed1i \u01b0u. <\/span><span style=\"font-weight: 400;\">TRUNCATE<\/span><span style=\"font-weight: 400;\"> s\u1ebd ph\u00f9 h\u1ee3p h\u01a1n do hi\u1ec7u su\u1ea5t cao h\u01a1n v\u00e0 gi\u1ea3i ph\u00f3ng b\u1ed9 nh\u1edb nhanh ch\u00f3ng.<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Cau_hoi_thuong_gap_ve_cau_lenh_DELETE_trong_SQL\"><\/span><b>C\u00e2u h\u1ecfi th\u01b0\u1eddng g\u1eb7p v\u1ec1 c\u00e2u l\u1ec7nh DELETE trong SQL<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><b>C\u00f3 th\u1ec3 x\u00f3a t\u1ea5t c\u1ea3 d\u1eef li\u1ec7u trong b\u1ea3ng m\u00e0 kh\u00f4ng x\u00f3a c\u1ea5u tr\u00fac b\u1ea3ng kh\u00f4ng?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">C\u00f3, b\u1ea1n c\u00f3 th\u1ec3 x\u00f3a t\u1ea5t c\u1ea3 d\u1eef li\u1ec7u trong b\u1ea3ng m\u00e0 v\u1eabn gi\u1eef nguy\u00ean c\u1ea5u tr\u00fac b\u1ea3ng b\u1eb1ng c\u00e1ch s\u1eed d\u1ee5ng:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">DELETE<\/span><span style=\"font-weight: 400;\">: S\u1eed d\u1ee5ng c\u00fa ph\u00e1p <\/span><span style=\"font-weight: 400;\">DELETE FROM table_name;<\/span><span style=\"font-weight: 400;\"> \u0111\u1ec3 x\u00f3a to\u00e0n b\u1ed9 d\u1eef li\u1ec7u. Ph\u01b0\u01a1ng ph\u00e1p n\u00e0y ghi t\u1eebng thao t\u00e1c x\u00f3a v\u00e0o nh\u1eadt k\u00fd giao d\u1ecbch.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">TRUNCATE<\/span><span style=\"font-weight: 400;\">: S\u1eed d\u1ee5ng c\u00fa ph\u00e1p <\/span><span style=\"font-weight: 400;\">TRUNCATE TABLE table_name;<\/span><span style=\"font-weight: 400;\"> \u0111\u1ec3 x\u00f3a nhanh to\u00e0n b\u1ed9 d\u1eef li\u1ec7u m\u00e0 kh\u00f4ng ghi t\u1eebng thao t\u00e1c v\u00e0o nh\u1eadt k\u00fd giao d\u1ecbch. Tuy nhi\u00ean, <\/span><span style=\"font-weight: 400;\">TRUNCATE<\/span><span style=\"font-weight: 400;\"> kh\u00f4ng cho ph\u00e9p s\u1eed d\u1ee5ng \u0111i\u1ec1u ki\u1ec7n v\u00e0 kh\u00f4ng th\u1ec3 d\u00f9ng tr\u00ean b\u1ea3ng c\u00f3 kh\u00f3a ngo\u1ea1i r\u00e0ng bu\u1ed9c.<\/span><\/li>\n<\/ul>\n<h3><b>C\u00f3 th\u1ec3 x\u00f3a d\u1eef li\u1ec7u t\u1eeb nhi\u1ec1u b\u1ea3ng c\u00f9ng l\u00fac kh\u00f4ng?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Kh\u00f4ng, l\u1ec7nh <\/span><span style=\"font-weight: 400;\">DELETE<\/span><span style=\"font-weight: 400;\"> ch\u1ec9 ho\u1ea1t \u0111\u1ed9ng tr\u00ean m\u1ed9t b\u1ea3ng t\u1ea1i m\u1ed9t th\u1eddi \u0111i\u1ec3m. \u0110\u1ec3 x\u00f3a d\u1eef li\u1ec7u t\u1eeb nhi\u1ec1u b\u1ea3ng, c\u1ea7n s\u1eed d\u1ee5ng nhi\u1ec1u c\u00e2u l\u1ec7nh <\/span><span style=\"font-weight: 400;\">DELETE<\/span><span style=\"font-weight: 400;\"> ri\u00eang bi\u1ec7t ho\u1eb7c vi\u1ebft c\u00e1c truy v\u1ea5n ph\u1ee9c t\u1ea1p v\u1edbi c\u00e1c b\u1ea3ng li\u00ean k\u1ebft.<\/span><\/p>\n<h3><b>C\u00f3 th\u1ec3 kh\u00f4i ph\u1ee5c d\u1eef li\u1ec7u sau khi d\u00f9ng DELETE kh\u00f4ng?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Kh\u00f4ng th\u1ec3 kh\u00f4i ph\u1ee5c d\u1eef li\u1ec7u sau khi d\u00f9ng <\/span><span style=\"font-weight: 400;\">DELETE<\/span><span style=\"font-weight: 400;\"> n\u1ebfu l\u1ec7nh \u0111\u00e3 \u0111\u01b0\u1ee3c cam k\u1ebft (commit). \u0110\u1ec3 kh\u00f4i ph\u1ee5c, b\u1ea1n c\u1ea7n c\u00f3 b\u1ea3n sao l\u01b0u ho\u1eb7c s\u1eed d\u1ee5ng giao d\u1ecbch (transaction) v\u00e0 th\u1ef1c hi\u1ec7n <\/span><span style=\"font-weight: 400;\">ROLLBACK<\/span><span style=\"font-weight: 400;\"> tr\u01b0\u1edbc khi th\u1ef1c thi.<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Tong_ket_cau_lenh_DELETE_trong_SQL\"><\/span><b>T\u1ed5ng k\u1ebft c\u00e2u l\u1ec7nh DELETE trong SQL<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">C\u00e2u l\u1ec7nh DELETE trong SQL l\u00e0 c\u00f4ng c\u1ee5 m\u1ea1nh m\u1ebd v\u00e0 linh ho\u1ea1t \u0111\u1ec3 x\u00f3a d\u1eef li\u1ec7u trong SQL, nh\u01b0ng c\u0169ng \u0111\u00f2i h\u1ecfi s\u1ef1 c\u1ea9n th\u1eadn v\u00e0 hi\u1ec3u bi\u1ebft r\u00f5 r\u00e0ng \u0111\u1ec3 s\u1eed d\u1ee5ng \u0111\u00fang c\u00e1ch. Vi\u1ec7c n\u1eafm v\u1eefng c\u00fa ph\u00e1p, c\u00e1c tr\u01b0\u1eddng h\u1ee3p \u00e1p d\u1ee5ng v\u00e0 h\u1ea1n ch\u1ebf c\u1ee7a <\/span><span style=\"font-weight: 400;\">DELETE<\/span><span style=\"font-weight: 400;\"> s\u1ebd gi\u00fap b\u1ea1n t\u1ed1i \u01b0u h\u00f3a quy tr\u00ecnh qu\u1ea3n l\u00fd d\u1eef li\u1ec7u.\u00a0<\/span><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 t\u1ed5ng quan v\u1ec1 l\u1ec7nh <\/span><span style=\"font-weight: 400;\">DELETE<\/span><span style=\"font-weight: 400;\"> v\u00e0 c\u00e1ch s\u1eed d\u1ee5ng sao cho hi\u1ec7u qu\u1ea3.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Tham kh\u1ea3o c\u00e1c b\u00e0i vi\u1ebft kh\u00e1c v\u1ec1 c\u00e1c l\u1ec7nh v\u00e0 thao t\u00e1c quan tr\u1ecdng trong SQL:<\/span><\/p>\n<ul>\n<li><a href=\"https:\/\/itviec.com\/blog\/tong-hop-cau-lenh-sql\/\" target=\"_blank\" rel=\"noopener\">C\u00e2u l\u1ec7nh SQL: T\u1ed5ng h\u1ee3p c\u00e1c c\u00e2u l\u1ec7nh, to\u00e1n t\u1eed v\u00e0 r\u00e0ng bu\u1ed9c SQL<\/a><\/li>\n<li><a href=\"https:\/\/itviec.com\/blog\/function-trong-sql\/\" target=\"_blank\" rel=\"noopener\">T\u1ed5ng h\u1ee3p 90+ function trong SQL c\u1ea7n bi\u1ebft<\/a><\/li>\n<li><a href=\"https:\/\/itviec.com\/blog\/select-trong-sql\/\" target=\"_blank\" rel=\"noopener\">SELECT trong SQL: H\u01b0\u1edbng d\u1eabn c\u00e1c c\u00e1ch \u1ee9ng d\u1ee5ng l\u1ec7nh SELECT<\/a><\/li>\n<li><a href=\"https:\/\/itviec.com\/blog\/cau-lenh-insert-trong-sql\/\" target=\"_blank\" rel=\"noopener\">C\u00e2u l\u1ec7nh INSERT trong SQL: C\u00fa ph\u00e1p v\u00e0 c\u00e1ch ho\u1ea1t \u0111\u1ed9ng<\/a><\/li>\n<li><a href=\"https:\/\/itviec.com\/blog\/cau-lenh-update-trong-sql\/\" target=\"_blank\" rel=\"noopener\">C\u00e2u l\u1ec7nh Update trong SQL: C\u00e1c th\u00e0nh ph\u1ea7n v\u00e0 c\u00e1ch ho\u1ea1t \u0111\u1ed9ng<\/a><\/li>\n<li><a href=\"https:\/\/itviec.com\/blog\/trigger-trong-sql\/\" target=\"_blank\" rel=\"noopener\">Trigger trong SQL: Chi ti\u1ebft c\u00e1c thao t\u00e1c trigger SQL c\u01a1 b\u1ea3n<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>C\u00e2u l\u1ec7nh DELETE trong SQL \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 x\u00f3a d\u1eef li\u1ec7u kh\u00f4ng c\u1ea7n thi\u1ebft t\u1eeb c\u01a1 s\u1edf d\u1eef li\u1ec7u. Hi\u1ec3u c\u00e1ch ho\u1ea1t \u0111\u1ed9ng v\u00e0 \u00e1p d\u1ee5ng l\u1ec7nh DELETE gi\u00fap b\u1ea1n qu\u1ea3n l\u00fd d\u1eef li\u1ec7u hi\u1ec7u qu\u1ea3, tr\u00e1nh r\u1ee7i ro m\u1ea5t d\u1eef li\u1ec7u kh\u00f4ng mong mu\u1ed1n. \u0110\u1ecdc b\u00e0i vi\u1ebft n\u00e0y \u0111\u1ec3 hi\u1ec3u r\u00f5 h\u01a1n v\u1ec1: [&hellip;]<\/p>\n","protected":false},"author":209,"featured_media":84499,"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-84495","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>C\u00e2u l\u1ec7nh DELETE trong SQL l\u00e0 g\u00ec? H\u01b0\u1edbng d\u1eabn s\u1eed d\u1ee5ng chi ti\u1ebft - ITviec Blog<\/title>\n<meta name=\"description\" content=\"N\u1eafm v\u1eefng t\u1ed5ng quan v\u1ec1 c\u00e2u l\u1ec7nh DELETE trong SQL v\u1edbi c\u00fa ph\u00e1p, v\u00ed d\u1ee5 chi ti\u1ebft cho t\u1eebng tr\u01b0\u1eddng h\u1ee3p s\u1eed d\u1ee5ng v\u00e0 m\u1ed9t s\u1ed1 l\u01b0u \u00fd khi s\u1eed d\u1ee5ng.\" \/>\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\/cau-lenh-delete-trong-sql\/\" \/>\n<meta property=\"og:locale\" content=\"vi_VN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C\u00e2u l\u1ec7nh DELETE trong SQL l\u00e0 g\u00ec? H\u01b0\u1edbng d\u1eabn s\u1eed d\u1ee5ng chi ti\u1ebft\" \/>\n<meta property=\"og:description\" content=\"C\u00e2u l\u1ec7nh DELETE trong SQL \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 x\u00f3a d\u1eef li\u1ec7u kh\u00f4ng c\u1ea7n thi\u1ebft t\u1eeb c\u01a1 s\u1edf d\u1eef li\u1ec7u. Hi\u1ec3u c\u00e1ch ho\u1ea1t \u0111\u1ed9ng v\u00e0 \u00e1p d\u1ee5ng l\u1ec7nh DELETE gi\u00fap b\u1ea1n qu\u1ea3n l\u00fd d\u1eef\" \/>\n<meta property=\"og:url\" content=\"https:\/\/itviec.com\/blog\/cau-lenh-delete-trong-sql\/\" \/>\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=\"2025-02-18T09:43:39+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/02\/cau-lenh-delete-trong-sql-vippro.jpeg\" \/>\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=\"9 ph\u00fat\" \/>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"C\u00e2u l\u1ec7nh DELETE trong SQL l\u00e0 g\u00ec? H\u01b0\u1edbng d\u1eabn s\u1eed d\u1ee5ng chi ti\u1ebft - ITviec Blog","description":"N\u1eafm v\u1eefng t\u1ed5ng quan v\u1ec1 c\u00e2u l\u1ec7nh DELETE trong SQL v\u1edbi c\u00fa ph\u00e1p, v\u00ed d\u1ee5 chi ti\u1ebft cho t\u1eebng tr\u01b0\u1eddng h\u1ee3p s\u1eed d\u1ee5ng v\u00e0 m\u1ed9t s\u1ed1 l\u01b0u \u00fd khi s\u1eed d\u1ee5ng.","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\/cau-lenh-delete-trong-sql\/","og_locale":"vi_VN","og_type":"article","og_title":"C\u00e2u l\u1ec7nh DELETE trong SQL l\u00e0 g\u00ec? H\u01b0\u1edbng d\u1eabn s\u1eed d\u1ee5ng chi ti\u1ebft","og_description":"C\u00e2u l\u1ec7nh DELETE trong SQL \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 x\u00f3a d\u1eef li\u1ec7u kh\u00f4ng c\u1ea7n thi\u1ebft t\u1eeb c\u01a1 s\u1edf d\u1eef li\u1ec7u. Hi\u1ec3u c\u00e1ch ho\u1ea1t \u0111\u1ed9ng v\u00e0 \u00e1p d\u1ee5ng l\u1ec7nh DELETE gi\u00fap b\u1ea1n qu\u1ea3n l\u00fd d\u1eef","og_url":"https:\/\/itviec.com\/blog\/cau-lenh-delete-trong-sql\/","og_site_name":"ITviec Blog","article_publisher":"https:\/\/www.facebook.com\/ITviec","article_published_time":"2025-02-18T09:43:39+00:00","og_image":[{"width":1500,"height":790,"url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/02\/cau-lenh-delete-trong-sql-vippro.jpeg","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":"9 ph\u00fat"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/itviec.com\/blog\/cau-lenh-delete-trong-sql\/#article","isPartOf":{"@id":"https:\/\/itviec.com\/blog\/cau-lenh-delete-trong-sql\/"},"author":{"name":"M\u1ef9 Duy\u00ean","@id":"https:\/\/itviec.com\/blog\/#\/schema\/person\/73733c0725c7e39e696a896bd1abe2d7"},"headline":"C\u00e2u l\u1ec7nh DELETE trong SQL l\u00e0 g\u00ec? H\u01b0\u1edbng d\u1eabn s\u1eed d\u1ee5ng chi ti\u1ebft","datePublished":"2025-02-18T09:43:39+00:00","mainEntityOfPage":{"@id":"https:\/\/itviec.com\/blog\/cau-lenh-delete-trong-sql\/"},"wordCount":2215,"publisher":{"@id":"https:\/\/itviec.com\/blog\/#organization"},"image":{"@id":"https:\/\/itviec.com\/blog\/cau-lenh-delete-trong-sql\/#primaryimage"},"thumbnailUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/02\/cau-lenh-delete-trong-sql-vippro.jpeg","articleSection":["Chuy\u00ean m\u00f4n IT"],"inLanguage":"vi"},{"@type":"WebPage","@id":"https:\/\/itviec.com\/blog\/cau-lenh-delete-trong-sql\/","url":"https:\/\/itviec.com\/blog\/cau-lenh-delete-trong-sql\/","name":"C\u00e2u l\u1ec7nh DELETE trong SQL l\u00e0 g\u00ec? H\u01b0\u1edbng d\u1eabn s\u1eed d\u1ee5ng chi ti\u1ebft - ITviec Blog","isPartOf":{"@id":"https:\/\/itviec.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/itviec.com\/blog\/cau-lenh-delete-trong-sql\/#primaryimage"},"image":{"@id":"https:\/\/itviec.com\/blog\/cau-lenh-delete-trong-sql\/#primaryimage"},"thumbnailUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/02\/cau-lenh-delete-trong-sql-vippro.jpeg","datePublished":"2025-02-18T09:43:39+00:00","description":"N\u1eafm v\u1eefng t\u1ed5ng quan v\u1ec1 c\u00e2u l\u1ec7nh DELETE trong SQL v\u1edbi c\u00fa ph\u00e1p, v\u00ed d\u1ee5 chi ti\u1ebft cho t\u1eebng tr\u01b0\u1eddng h\u1ee3p s\u1eed d\u1ee5ng v\u00e0 m\u1ed9t s\u1ed1 l\u01b0u \u00fd khi s\u1eed d\u1ee5ng.","breadcrumb":{"@id":"https:\/\/itviec.com\/blog\/cau-lenh-delete-trong-sql\/#breadcrumb"},"inLanguage":"vi","potentialAction":[{"@type":"ReadAction","target":["https:\/\/itviec.com\/blog\/cau-lenh-delete-trong-sql\/"]}]},{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/itviec.com\/blog\/cau-lenh-delete-trong-sql\/#primaryimage","url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/02\/cau-lenh-delete-trong-sql-vippro.jpeg","contentUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/02\/cau-lenh-delete-trong-sql-vippro.jpeg","width":1500,"height":790,"caption":"c\u00e2u l\u1ec7nh delete trong sql - itviec blog"},{"@type":"BreadcrumbList","@id":"https:\/\/itviec.com\/blog\/cau-lenh-delete-trong-sql\/#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":"C\u00e2u l\u1ec7nh DELETE trong SQL l\u00e0 g\u00ec? H\u01b0\u1edbng d\u1eabn s\u1eed d\u1ee5ng chi ti\u1ebft"}]},{"@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\/84495","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=84495"}],"version-history":[{"count":0,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts\/84495\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/media\/84499"}],"wp:attachment":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/media?parent=84495"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/categories?post=84495"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/tags?post=84495"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}