{"id":84364,"date":"2025-02-01T22:49:02","date_gmt":"2025-02-01T15:49:02","guid":{"rendered":"https:\/\/itviec.com\/blog\/?p=84364"},"modified":"2025-02-01T22:49:46","modified_gmt":"2025-02-01T15:49:46","slug":"cau-lenh-insert-trong-sql","status":"publish","type":"post","link":"https:\/\/itviec.com\/blog\/cau-lenh-insert-trong-sql\/","title":{"rendered":"C\u00e2u l\u1ec7nh INSERT trong SQL: C\u00fa ph\u00e1p v\u00e0 c\u00e1ch ho\u1ea1t \u0111\u1ed9ng"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 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-insert-trong-sql\/#Tong_quan_ve_cau_lenh_INSERT_trong_SQL\" >T\u1ed5ng quan v\u1ec1 c\u00e2u l\u1ec7nh INSERT trong SQL<\/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-insert-trong-sql\/#Thanh_phan_cua_cau_lenh_INSERT_trong_SQL\" >Th\u00e0nh ph\u1ea7n c\u1ee7a c\u00e2u l\u1ec7nh INSERT 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-insert-trong-sql\/#Cau_lenh_INSERT_trong_SQL_hoat_dong_nhu_the_nao\" >C\u00e2u\u00a0l\u1ec7nh INSERT trong SQL ho\u1ea1t \u0111\u1ed9ng nh\u01b0 th\u1ebf n\u00e0o?<\/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-insert-trong-sql\/#Cac_truong_hop_su_dung_cau_lenh_INSERT_trong_SQL\" >C\u00e1c tr\u01b0\u1eddng h\u1ee3p s\u1eed d\u1ee5ng c\u00e2u l\u1ec7nh INSERT 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-insert-trong-sql\/#Cau_hoi_thuong_gap_ve_cau_lenh_INSERT_trong_SQL\" >C\u00e2u h\u1ecfi th\u01b0\u1eddng g\u1eb7p v\u1ec1 c\u00e2u l\u1ec7nh INSERT trong SQL<\/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\/cau-lenh-insert-trong-sql\/#Tong_ket_cau_lenh_INSERT_trong_SQL\" >T\u1ed5ng k\u1ebft c\u00e2u l\u1ec7nh INSERT trong SQL<\/a><\/li><\/ul><\/nav><\/div>\n<p><em><strong>C\u00e2u l\u1ec7nh INSERT trong SQL l\u00e0 m\u1ed9t c\u00f4ng c\u1ee5 thi\u1ebft y\u1ebfu \u0111\u1ec3 th\u00eam d\u1eef li\u1ec7u m\u1edbi v\u00e0o c\u00e1c b\u1ea3ng trong c\u01a1 s\u1edf d\u1eef li\u1ec7u. T\u1eeb vi\u1ec7c ch\u00e8n m\u1ed9t b\u1ea3n ghi \u0111\u01a1n gi\u1ea3n, th\u00eam nhi\u1ec1u b\u1ea3n ghi c\u00f9ng l\u00fac, \u0111\u1ebfn sao ch\u00e9p d\u1eef li\u1ec7u t\u1eeb c\u00e1c b\u1ea3ng kh\u00e1c, l\u1ec7nh n\u00e0y mang l\u1ea1i s\u1ef1 linh ho\u1ea1t v\u00e0 hi\u1ec7u qu\u1ea3 trong qu\u1ea3n l\u00fd d\u1eef li\u1ec7u.<\/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;\">C\u00fa ph\u00e1p v\u00e0 c\u00e1ch ho\u1ea1t \u0111\u1ed9ng c\u1ee7a l\u1ec7nh INSERT<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">\u1ee8ng d\u1ee5ng c\u1ee7a l\u1ec7nh INSERT trong th\u1ef1c t\u1ebf<\/span><\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Tong_quan_ve_cau_lenh_INSERT_trong_SQL\"><\/span><b>T\u1ed5ng quan v\u1ec1 c\u00e2u l\u1ec7nh INSERT trong SQL<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">L\u1ec7nh INSERT l\u00e0 l\u1ec7nh d\u00f9ng \u0111\u1ec3 th\u00eam d\u1eef li\u1ec7u m\u1edbi v\u00e0o b\u1ea3ng trong c\u01a1 s\u1edf d\u1eef li\u1ec7u. V\u1edbi l\u1ec7nh n\u00e0y, ta c\u00f3 th\u1ec3 th\u00eam m\u1ed9t ho\u1eb7c nhi\u1ec1u b\u1ea3n ghi c\u00f9ng l\u00fac t\u00f9y thu\u1ed9c v\u00e0o nhu c\u1ea7u. INSERT th\u01b0\u1eddng \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng trong c\u00e1c \u1ee9ng d\u1ee5ng th\u1ef1c t\u1ebf nh\u01b0 l\u01b0u th\u00f4ng tin kh\u00e1ch h\u00e0ng m\u1edbi, th\u00eam s\u1ea3n ph\u1ea9m v\u00e0o danh s\u00e1ch ho\u1eb7c ghi nh\u1eadn giao d\u1ecbch m\u1edbi.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u0110\u00e2y l\u00e0 m\u1ed9t c\u00f4ng c\u1ee5 c\u01a1 b\u1ea3n nh\u01b0ng r\u1ea5t m\u1ea1nh m\u1ebd \u0111\u1ec3 x\u00e2y d\u1ef1ng v\u00e0 qu\u1ea3n l\u00fd d\u1eef li\u1ec7u trong c\u01a1 s\u1edf d\u1eef li\u1ec7u, gi\u00fap h\u1ec7 th\u1ed1ng ho\u1ea1t \u0111\u1ed9ng hi\u1ec7u qu\u1ea3 v\u00e0 ch\u00ednh x\u00e1c.<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Thanh_phan_cua_cau_lenh_INSERT_trong_SQL\"><\/span><b>Th\u00e0nh ph\u1ea7n c\u1ee7a c\u00e2u l\u1ec7nh INSERT trong SQL<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">L\u1ec7nh INSERT trong SQL c\u00f3 c\u00fa ph\u00e1p c\u01a1 b\u1ea3n nh\u01b0 sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">INSERT INTO table_name (column1, column2, column3, ...)<\/span>\r\n\r\n<span style=\"font-weight: 400;\">VALUES (value1, value2, value3, ...);<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">C\u00e1c th\u00e0nh ph\u1ea7n ch\u00ednh bao g\u1ed3m:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">INSERT INTO table_name<\/span><span style=\"font-weight: 400;\">: X\u00e1c \u0111\u1ecbnh t\u00ean b\u1ea3ng m\u00e0 b\u1ea1n mu\u1ed1n th\u00eam d\u1eef li\u1ec7u.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><i><span style=\"font-weight: 400;\">Danh s\u00e1ch c\u1ed9t<\/span><\/i><span style=\"font-weight: 400;\">: X\u00e1c \u0111\u1ecbnh c\u00e1c c\u1ed9t m\u00e0 d\u1eef li\u1ec7u s\u1ebd \u0111\u01b0\u1ee3c th\u00eam v\u00e0o. N\u1ebfu b\u1ecf qua, d\u1eef li\u1ec7u s\u1ebd \u0111\u01b0\u1ee3c th\u00eam theo th\u1ee9 t\u1ef1 m\u1eb7c \u0111\u1ecbnh c\u1ee7a t\u1ea5t c\u1ea3 c\u00e1c c\u1ed9t trong b\u1ea3ng.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">VALUES<\/span><span style=\"font-weight: 400;\">: Ch\u1ec9 \u0111\u1ecbnh c\u00e1c gi\u00e1 tr\u1ecb c\u1ea7n th\u00eam v\u00e0o b\u1ea3ng t\u01b0\u01a1ng \u1ee9ng v\u1edbi s\u1ed1 l\u01b0\u1ee3ng v\u00e0 ki\u1ec3u d\u1eef li\u1ec7u c\u1ee7a danh s\u00e1ch c\u1ed9t \u0111\u01b0\u1ee3c khai b\u00e1o. N\u1ebfu danh s\u00e1ch c\u1ed9t kh\u00f4ng \u0111\u01b0\u1ee3c ch\u1ec9 \u0111\u1ecbnh, gi\u00e1 tr\u1ecb ph\u1ea3i kh\u1edbp v\u1edbi danh s\u00e1ch c\u1ed9t m\u1eb7c \u0111\u1ecbnh c\u1ee7a b\u1ea3ng.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><i><span style=\"font-weight: 400;\">Truy v\u1ea5n con (tu\u1ef3 ch\u1ecdn)<\/span><\/i><span style=\"font-weight: 400;\">: Thay v\u00ec VALUES, b\u1ea1n c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng m\u1ed9t truy v\u1ea5n con \u0111\u1ec3 ch\u00e8n d\u1eef li\u1ec7u t\u1eeb m\u1ed9t b\u1ea3ng kh\u00e1c.<\/span><\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Cau_lenh_INSERT_trong_SQL_hoat_dong_nhu_the_nao\"><\/span><b>C\u00e2u\u00a0l\u1ec7nh INSERT trong SQL ho\u1ea1t \u0111\u1ed9ng nh\u01b0 th\u1ebf n\u00e0o?<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Khi th\u1ef1c thi l\u1ec7nh INSERT, h\u1ec7 qu\u1ea3n tr\u1ecb c\u01a1 s\u1edf d\u1eef li\u1ec7u th\u1ef1c hi\u1ec7n c\u00e1c b\u01b0\u1edbc sau:<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>X\u00e1c \u0111\u1ecbnh b\u1ea3ng m\u1ee5c ti\u00eau<\/b><span style=\"font-weight: 400;\">: H\u1ec7 th\u1ed1ng x\u00e1c \u0111\u1ecbnh b\u1ea3ng \u0111\u01b0\u1ee3c ch\u1ec9 \u0111\u1ecbnh trong c\u00e2u l\u1ec7nh <\/span><span style=\"font-weight: 400;\">INSERT INTO<\/span><span style=\"font-weight: 400;\">.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Ki\u1ec3m tra c\u1ed9t v\u00e0 gi\u00e1 tr\u1ecb<\/b><span style=\"font-weight: 400;\">: X\u00e1c minh danh s\u00e1ch c\u1ed9t (n\u1ebfu c\u00f3) v\u00e0 ki\u1ec3m tra s\u1ed1 l\u01b0\u1ee3ng, ki\u1ec3u d\u1eef li\u1ec7u c\u1ee7a c\u00e1c gi\u00e1 tr\u1ecb trong m\u1ec7nh \u0111\u1ec1 <\/span><span style=\"font-weight: 400;\">VALUES<\/span><span style=\"font-weight: 400;\">. N\u1ebfu kh\u00f4ng cung c\u1ea5p danh s\u00e1ch c\u1ed9t, h\u1ec7 th\u1ed1ng s\u1ebd \u00e1p d\u1ee5ng gi\u00e1 tr\u1ecb cho t\u1ea5t c\u1ea3 c\u00e1c c\u1ed9t theo th\u1ee9 t\u1ef1 m\u1eb7c \u0111\u1ecbnh.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Th\u00eam d\u1eef li\u1ec7u m\u1edbi<\/b><span style=\"font-weight: 400;\">: M\u1ed9t b\u1ea3n ghi m\u1edbi \u0111\u01b0\u1ee3c t\u1ea1o v\u1edbi c\u00e1c gi\u00e1 tr\u1ecb \u0111\u01b0\u1ee3c cung c\u1ea5p v\u00e0 ch\u00e8n v\u00e0o b\u1ea3ng m\u1ee5c ti\u00eau. C\u00e1c gi\u00e1 tr\u1ecb m\u1eb7c \u0111\u1ecbnh ho\u1eb7c gi\u00e1 tr\u1ecb <\/span><span style=\"font-weight: 400;\">NULL<\/span><span style=\"font-weight: 400;\"> s\u1ebd \u0111\u01b0\u1ee3c \u00e1p d\u1ee5ng cho c\u1ed9t kh\u00f4ng c\u00f3 d\u1eef li\u1ec7u trong l\u1ec7nh.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Ki\u1ec3m tra r\u00e0ng bu\u1ed9c v\u00e0 ch\u1ec9 m\u1ee5c<\/b><span style=\"font-weight: 400;\">: R\u00e0ng bu\u1ed9c nh\u01b0 kh\u00f3a ch\u00ednh, kh\u00f3a ngo\u1ea1i ho\u1eb7c r\u00e0ng bu\u1ed9c NOT NULL \u0111\u01b0\u1ee3c ki\u1ec3m tra tr\u01b0\u1edbc khi ho\u00e0n t\u1ea5t. \u0110\u1ed3ng th\u1eddi, h\u1ec7 th\u1ed1ng s\u1ebd c\u1eadp nh\u1eadt ch\u1ec9 m\u1ee5c (index) n\u1ebfu c\u00f3 trong b\u1ea3ng.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>L\u01b0u tr\u1eef b\u1ea3n ghi<\/b><span style=\"font-weight: 400;\">: N\u1ebfu d\u1eef li\u1ec7u h\u1ee3p l\u1ec7, b\u1ea3n ghi m\u1edbi s\u1ebd \u0111\u01b0\u1ee3c l\u01b0u tr\u1eef trong b\u1ea3ng. N\u1ebfu c\u00f3 l\u1ed7i, l\u1ec7nh s\u1ebd b\u1ecb h\u1ee7y ho\u1eb7c ch\u1ec9 b\u1ecf qua b\u1ea3n ghi b\u1ecb l\u1ed7i, t\u00f9y thu\u1ed9c v\u00e0o c\u00e1ch x\u1eed l\u00fd c\u1ee7a h\u1ec7 qu\u1ea3n tr\u1ecb c\u01a1 s\u1edf d\u1eef li\u1ec7u.<\/span><\/li>\n<\/ol>\n<h2><span class=\"ez-toc-section\" id=\"Cac_truong_hop_su_dung_cau_lenh_INSERT_trong_SQL\"><\/span><b>C\u00e1c tr\u01b0\u1eddng h\u1ee3p s\u1eed d\u1ee5ng c\u00e2u l\u1ec7nh INSERT trong SQL<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><b>Th\u00eam m\u1ed9t b\u1ea3n ghi (Insert Single Row)<\/b><\/h3>\n<h4><b>Th\u00eam d\u1eef li\u1ec7u c\u01a1 b\u1ea3n<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">\u0110\u00e2y l\u00e0 tr\u01b0\u1eddng h\u1ee3p \u0111\u01a1n gi\u1ea3n nh\u1ea5t, s\u1eed d\u1ee5ng khi b\u1ea1n mu\u1ed1n th\u00eam m\u1ed9t d\u00f2ng d\u1eef li\u1ec7u v\u00e0o b\u1ea3ng. N\u1ebfu b\u1ea3ng c\u00f3 c\u1ed9t id \u0111\u01b0\u1ee3c thi\u1ebft l\u1eadp t\u1ef1 \u0111\u1ed9ng t\u0103ng (AUTO_INCREMENT), b\u1ea1n kh\u00f4ng c\u1ea7n t\u1ef1 \u0111i\u1ec1n gi\u00e1 tr\u1ecb cho c\u1ed9t id v\u00ec h\u1ec7 th\u1ed1ng s\u1ebd t\u1ef1 \u0111\u1ed9ng t\u1ea1o v\u00e0 t\u0103ng gi\u00e1 tr\u1ecb n\u00e0y m\u1ed7i khi b\u1ea1n th\u00eam m\u1ed9t d\u00f2ng d\u1eef li\u1ec7u m\u1edbi.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5: Gi\u1ea3 s\u1eed ta c\u00f3 b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">Employees<\/span><\/i><span style=\"font-weight: 400;\"> v\u1edbi c\u00e1c thu\u1ed9c t\u00ednh: <\/span><i><span style=\"font-weight: 400;\">id (AUTO_INCREMENT)<\/span><\/i><span style=\"font-weight: 400;\">, <\/span><i><span style=\"font-weight: 400;\">name<\/span><\/i><span style=\"font-weight: 400;\">, <\/span><i><span style=\"font-weight: 400;\">age<\/span><\/i><span style=\"font-weight: 400;\">, <\/span><i><span style=\"font-weight: 400;\">position<\/span><\/i><span style=\"font-weight: 400;\">. \u0110\u1ec3 th\u00eam th\u00f4ng tin nh\u00e2n vi\u00ean Alice v\u00e0o b\u1ea3ng Employees, ta s\u1eed d\u1ee5ng c\u00fa ph\u00e1p:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">INSERT INTO Employees (name, age, position)<\/span>\r\n\r\n<span style=\"font-weight: 400;\">VALUES ('Alice', 25, 'Developer');<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">K\u1ebft qu\u1ea3 sau khi th\u1ef1c hi\u1ec7n l\u1ec7nh:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>id<\/b><\/td>\n<td><b>name<\/b><\/td>\n<td><b>age<\/b><\/td>\n<td><b>position<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">1<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Alice<\/span><\/td>\n<td><span style=\"font-weight: 400;\">25<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Developer<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\">Gi\u1ea3i th\u00edch: \u1ede \u0111\u00e2y, h\u1ec7 th\u1ed1ng t\u1ef1 \u0111\u1ed9ng g\u00e1n <\/span><span style=\"font-weight: 400;\">id = 1<\/span><span style=\"font-weight: 400;\"> cho b\u1ea3n ghi m\u1edbi, m\u00e0 b\u1ea1n kh\u00f4ng c\u1ea7n ch\u1ec9 \u0111\u1ecbnh gi\u00e1 tr\u1ecb n\u00e0y trong c\u00e2u l\u1ec7nh <\/span><span style=\"font-weight: 400;\">INSERT<\/span><span style=\"font-weight: 400;\">, gi\u00fap b\u1ea1n ti\u1ebft ki\u1ec7m th\u1eddi gian v\u00e0 tr\u00e1nh l\u1ed7i khi l\u00e0m vi\u1ec7c v\u1edbi c\u00e1c gi\u00e1 tr\u1ecb <\/span><i><span style=\"font-weight: 400;\">id<\/span><\/i><span style=\"font-weight: 400;\">.<\/span><\/p>\n<h4><b>Th\u00eam d\u1eef li\u1ec7u t\u1ef1 \u0111\u1ed9ng \u0111i\u1ec1n gi\u00e1 tr\u1ecb m\u1eb7c \u0111\u1ecbnh<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">B\u00ean c\u1ea1nh \u0111\u00f3, khi b\u1ea3ng c\u00f3 c\u00e1c c\u1ed9t \u0111\u01b0\u1ee3c c\u1ea5u h\u00ecnh gi\u00e1 tr\u1ecb m\u1eb7c \u0111\u1ecbnh, ta c\u00f3 th\u1ec3 b\u1ecf qua vi\u1ec7c cung c\u1ea5p gi\u00e1 tr\u1ecb cho c\u00e1c c\u1ed9t \u0111\u00f3. Nh\u01b0 trong MySQL, n\u1ebfu m\u1ed9t c\u1ed9t \u0111\u01b0\u1ee3c thi\u1ebft l\u1eadp gi\u00e1 tr\u1ecb m\u1eb7c \u0111\u1ecbnh b\u1eb1ng <\/span><span style=\"font-weight: 400;\">DEFAULT<\/span><span style=\"font-weight: 400;\">, b\u1ea1n c\u00f3 th\u1ec3 b\u1ecf qua n\u00f3 khi th\u00eam d\u1eef li\u1ec7u.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5: Ta c\u00f3 b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">Orders<\/span><\/i><span style=\"font-weight: 400;\"> v\u1edbi c\u00e1c c\u1ed9t <\/span><i><span style=\"font-weight: 400;\">customer_id<\/span><\/i><span style=\"font-weight: 400;\">, <\/span><i><span style=\"font-weight: 400;\">product_id<\/span><\/i><span style=\"font-weight: 400;\">, <\/span><i><span style=\"font-weight: 400;\">created_at<\/span><\/i><span style=\"font-weight: 400;\"> (trong \u0111\u00f3 <\/span><i><span style=\"font-weight: 400;\">created_at<\/span><\/i><span style=\"font-weight: 400;\"> m\u1eb7c \u0111\u1ecbnh l\u00e0 ng\u00e0y hi\u1ec7n t\u1ea1i <\/span><i><span style=\"font-weight: 400;\">CURRENT_DATE<\/span><\/i><span style=\"font-weight: 400;\">). \u0110\u1ec3 th\u00eam m\u1ed9t b\u1ea3n ghi m\u00e0 kh\u00f4ng c\u1ea7n cung c\u1ea5p gi\u00e1 tr\u1ecb cho <\/span><i><span style=\"font-weight: 400;\">order_date<\/span><\/i><span style=\"font-weight: 400;\">, ta s\u1eed d\u1ee5ng c\u00fa ph\u00e1p sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">INSERT INTO Orders (customer_id, product_id)<\/span>\r\n\r\n<span style=\"font-weight: 400;\">VALUES (1, 101);<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">K\u1ebft qu\u1ea3 sau khi th\u1ef1c hi\u1ec7n l\u1ec7nh:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>order_id<\/b><\/td>\n<td><b>customer_id<\/b><\/td>\n<td><b>product_id<\/b><\/td>\n<td><b>created_at<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">1<\/span><\/td>\n<td><span style=\"font-weight: 400;\">1<\/span><\/td>\n<td><span style=\"font-weight: 400;\">101<\/span><\/td>\n<td><span style=\"font-weight: 400;\">2025-01-25<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\">Gi\u1ea3i th\u00edch: L\u1ec7nh tr\u00ean s\u1ebd th\u00eam m\u1ed9t \u0111\u01a1n h\u00e0ng m\u1edbi v\u00e0o b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">Orders<\/span><\/i><span style=\"font-weight: 400;\"> v\u1edbi gi\u00e1 tr\u1ecb <\/span><i><span style=\"font-weight: 400;\">created_at<\/span><\/i><span style=\"font-weight: 400;\"> t\u1ef1 \u0111\u1ed9ng nh\u1eadn gi\u00e1 tr\u1ecb l\u00e0 ng\u00e0y hi\u1ec7n t\u1ea1i (<\/span><i><span style=\"font-weight: 400;\">CURRENT_DATE<\/span><\/i><span style=\"font-weight: 400;\">).<\/span><\/p>\n<h4><b>Th\u00eam d\u1eef li\u1ec7u v\u1edbi gi\u00e1 tr\u1ecb NULL<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">Khi kh\u00f4ng c\u00f3 gi\u00e1 tr\u1ecb c\u1ee5 th\u1ec3 \u0111\u1ec3 th\u00eam v\u00e0o m\u1ed9t s\u1ed1 c\u1ed9t, b\u1ea1n c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng <\/span><span style=\"font-weight: 400;\">NULL<\/span><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5: Ta c\u00f3 b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">Products<\/span><\/i><span style=\"font-weight: 400;\"> v\u1edbi c\u00e1c c\u1ed9t <\/span><i><span style=\"font-weight: 400;\">name<\/span><\/i><span style=\"font-weight: 400;\">, <\/span><i><span style=\"font-weight: 400;\">price<\/span><\/i><span style=\"font-weight: 400;\">, <\/span><i><span style=\"font-weight: 400;\">category<\/span><\/i><span style=\"font-weight: 400;\">, n\u1ebfu gi\u00e1 tr\u1ecb price ch\u01b0a \u0111\u01b0\u1ee3c x\u00e1c \u0111\u1ecbnh, ta c\u00f3 th\u1ec3 th\u00eam m\u1ed9t b\u1ea3n ghi v\u1edbi gi\u00e1 tr\u1ecb <\/span><span style=\"font-weight: 400;\">NULL<\/span><span style=\"font-weight: 400;\"> v\u1edbi c\u00fa ph\u00e1p nh\u01b0 sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">INSERT INTO Products (name, price, category)<\/span>\r\n\r\n<span style=\"font-weight: 400;\">VALUES ('Tablet', NULL, 'Electronics')<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0('Laptop', 1500, 'Electronics');<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">K\u1ebft qu\u1ea3 sau khi th\u1ef1c hi\u1ec7n l\u1ec7nh:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>product_id<\/b><\/td>\n<td><b>name<\/b><\/td>\n<td><b>price<\/b><\/td>\n<td><b>category<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">1<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tablet<\/span><\/td>\n<td><span style=\"font-weight: 400;\">NULL<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Electronics<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">2<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Laptop<\/span><\/td>\n<td><span style=\"font-weight: 400;\">1500<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Electronics<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\">Gi\u1ea3i th\u00edch: S\u1ea3n ph\u1ea9m <\/span><i><span style=\"font-weight: 400;\">Tablet<\/span><\/i><span style=\"font-weight: 400;\"> c\u00f3 gi\u00e1 tr\u1ecb <\/span><span style=\"font-weight: 400;\">price = NULL<\/span><span style=\"font-weight: 400;\"> v\u00ec gi\u00e1 ch\u01b0a x\u00e1c \u0111\u1ecbnh, trong khi s\u1ea3n ph\u1ea9m <\/span><i><span style=\"font-weight: 400;\">Laptop<\/span><\/i><span style=\"font-weight: 400;\"> \u0111\u01b0\u1ee3c nh\u1eadp \u0111\u1ea7y \u0111\u1ee7 th\u00f4ng tin.<\/span><\/p>\n<h4><b>Th\u00eam d\u1eef li\u1ec7u c\u00f3 \u0111i\u1ec1u ki\u1ec7n \u0111\u1ec3 ki\u1ec3m tra tr\u00f9ng l\u1eb7p:<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">\u0110\u1ec3 tr\u00e1nh tr\u00f9ng l\u1eb7p d\u1eef li\u1ec7u, ta c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng c\u00e1c c\u00e2u l\u1ec7nh ki\u1ec3m tra tr\u00f9ng l\u1eb7p tr\u01b0\u1edbc khi th\u00eam. T\u00f9y v\u00e0o m\u1ed7i h\u1ec7 qu\u1ea3n tr\u1ecb c\u01a1 s\u1edf d\u1eef li\u1ec7u th\u00ec c\u00fa ph\u00e1p s\u1ebd kh\u00e1c nhau.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 (v\u1edbi MySQL) \u0111\u1ec3 th\u00eam b\u1ea3n ghi v\u1ec1 nh\u00e2n vi\u00ean Alice v\u00e0 ki\u1ec3m tra xem \u0111\u00e3 c\u00f3 b\u1ea3n ghi tr\u00f9ng v\u1ec1 t\u00ean (name), tu\u1ed5i (age) v\u00e0 v\u1ecb tr\u00ed (position) ch\u01b0a, ta c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng c\u00fa ph\u00e1p sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">INSERT INTO Employees (id, name, age, position)<\/span>\r\n\r\n<span style=\"font-weight: 400;\">VALUES (1, 'Alice', 25, 'Developer')<\/span>\r\n\r\n<span style=\"font-weight: 400;\">ON DUPLICATE KEY UPDATE name = VALUES(name), age = VALUES(age), position = VALUES(position);<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">K\u1ebft qu\u1ea3 sau khi th\u1ef1c hi\u1ec7n l\u1ec7nh:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>id<\/b><\/td>\n<td><b>name<\/b><\/td>\n<td><b>age<\/b><\/td>\n<td><b>position<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">1<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Alice<\/span><\/td>\n<td><span style=\"font-weight: 400;\">25<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Developer<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\">Gi\u1ea3i th\u00edch: N\u1ebfu b\u1ea3n ghi v\u1edbi <\/span><span style=\"font-weight: 400;\">id = 1<\/span><span style=\"font-weight: 400;\"> \u0111\u00e3 t\u1ed3n t\u1ea1i, th\u00f4ng tin c\u1ee7a Alice s\u1ebd \u0111\u01b0\u1ee3c c\u1eadp nh\u1eadt thay v\u00ec th\u00eam b\u1ea3n ghi m\u1edbi.<\/span><\/p>\n<h3><b>Th\u00eam nhi\u1ec1u b\u1ea3n ghi c\u00f9ng l\u00fac (Insert Multiple Rows)<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Ta c\u00f3 th\u1ec3 th\u00eam nhi\u1ec1u b\u1ea3n ghi trong m\u1ed9t l\u1ec7nh duy nh\u1ea5t b\u1eb1ng c\u00e1ch cung c\u1ea5p nhi\u1ec1u gi\u00e1 tr\u1ecb trong m\u1ec7nh \u0111\u1ec1 <\/span><span style=\"font-weight: 400;\">VALUES<\/span><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5: \u0110\u1ec3 th\u00eam th\u00f4ng tin ba nh\u00e2n vi\u00ean m\u1edbi v\u00e0o b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">Employees<\/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;\">INSERT INTO Employees (name, age, position)<\/span>\r\n\r\n<span style=\"font-weight: 400;\">VALUES\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">('Bob', 30, 'Designer'),<\/span>\r\n\r\n<span style=\"font-weight: 400;\">('Charlie', 35, 'Manager'),<\/span>\r\n\r\n<span style=\"font-weight: 400;\">('Daisy', 28, 'Tester');<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">K\u1ebft qu\u1ea3 sau khi th\u1ef1c hi\u1ec7n l\u1ec7nh:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>id<\/b><\/td>\n<td><b>name<\/b><\/td>\n<td><b>age<\/b><\/td>\n<td><b>position<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">1<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Alice<\/span><\/td>\n<td><span style=\"font-weight: 400;\">25<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Developer<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">2<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Bob<\/span><\/td>\n<td><span style=\"font-weight: 400;\">30<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Designer<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">3<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Charlie<\/span><\/td>\n<td><span style=\"font-weight: 400;\">35<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Manager<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">4<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Daisy<\/span><\/td>\n<td><span style=\"font-weight: 400;\">28<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tester<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><b>Sao ch\u00e9p d\u1eef li\u1ec7u t\u1eeb m\u1ed9t b\u1ea3ng kh\u00e1c (Insert Using SELECT)<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">L\u1ec7nh <\/span><span style=\"font-weight: 400;\">INSERT<\/span><span style=\"font-weight: 400;\"> c\u00f3 th\u1ec3 k\u1ebft h\u1ee3p v\u1edbi c\u00e2u l\u1ec7nh <\/span><span style=\"font-weight: 400;\">SELECT<\/span><span style=\"font-weight: 400;\"> \u0111\u1ec3 sao ch\u00e9p d\u1eef li\u1ec7u t\u1eeb b\u1ea3ng n\u00e0y sang b\u1ea3ng kh\u00e1c. V\u00ed d\u1ee5: \u0110\u1ec3 sao ch\u00e9p t\u1ea5t c\u1ea3 c\u00e1c \u0111\u01a1n h\u00e0ng tr\u01b0\u1edbc ng\u00e0y 01\/01\/2024 t\u1eeb b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">Orders<\/span><\/i><span style=\"font-weight: 400;\"> sang b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">Archived_Orders<\/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;\">INSERT INTO Archived_Orders (order_id, customer_id, order_date)<\/span>\r\n\r\n<span style=\"font-weight: 400;\">SELECT order_id, customer_id, order_date<\/span>\r\n\r\n<span style=\"font-weight: 400;\">FROM Orders<\/span>\r\n\r\n<span style=\"font-weight: 400;\">WHERE order_date &lt; '2024-01-01';<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">B\u1ea3ng Archived_Oders sau khi th\u1ef1c th\u1ef1c hi\u1ec7n l\u1ec7nh:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td style=\"text-align: left;\"><b>order_id<\/b><\/td>\n<td><b>customer_id<\/b><\/td>\n<td><b>product_id<\/b><\/td>\n<td><b>created_at<\/b><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\">Gi\u1ea3i th\u00edch: Kh\u00f4ng c\u00f3 b\u1ea3n ghi n\u00e0o t\u1eeb b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">Orders<\/span><\/i><span style=\"font-weight: 400;\"> th\u1ecfa m\u00e3n \u0111i\u1ec1u ki\u1ec7n <\/span><span style=\"font-weight: 400;\">order_date &lt; &#8216;2024-01-01&#8217;<\/span><span style=\"font-weight: 400;\">, n\u00ean kh\u00f4ng c\u00f3 b\u1ea3n ghi n\u00e0o \u0111\u01b0\u1ee3c sao ch\u00e9p sang b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">Archived_Orders<\/span><\/i><span style=\"font-weight: 400;\">.<\/span><\/p>\n<h3><b>Th\u00eam d\u1eef li\u1ec7u b\u1eb1ng c\u00e1ch s\u1eed d\u1ee5ng truy v\u1ea5n ph\u1ee5<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Ngo\u00e0i ra, ta c\u00f3 th\u1ec3 ch\u00e8n d\u1eef li\u1ec7u d\u1ef1a tr\u00ean k\u1ebft qu\u1ea3 c\u1ee7a m\u1ed9t truy v\u1ea5n ph\u1ee5. Gi\u1ea3 s\u1eed ta c\u00f3 b\u1ea3ng Transactions nh\u01b0 sau:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>transaction_id<\/b><\/td>\n<td><b>customer_id<\/b><\/td>\n<td><b>amount<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">1<\/span><\/td>\n<td><span style=\"font-weight: 400;\">1<\/span><\/td>\n<td><span style=\"font-weight: 400;\">5000<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">2<\/span><\/td>\n<td><span style=\"font-weight: 400;\">1<\/span><\/td>\n<td><span style=\"font-weight: 400;\">10000<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">3<\/span><\/td>\n<td><span style=\"font-weight: 400;\">2<\/span><\/td>\n<td><span style=\"font-weight: 400;\">2000<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">4<\/span><\/td>\n<td><span style=\"font-weight: 400;\">3<\/span><\/td>\n<td><span style=\"font-weight: 400;\">7000<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">5<\/span><\/td>\n<td><span style=\"font-weight: 400;\">3<\/span><\/td>\n<td><span style=\"font-weight: 400;\">5000<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5: \u0110\u1ec3 th\u00eam v\u00e0o b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">HighValueCustomers<\/span><\/i><span style=\"font-weight: 400;\"> t\u1ea5t c\u1ea3 c\u00e1c kh\u00e1ch h\u00e0ng c\u00f3 t\u1ed5ng chi ti\u00eau v\u01b0\u1ee3t qu\u00e1 10,000 t\u1eeb b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">Transactions<\/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;\">INSERT INTO HighValueCustomers (customer_id, total_spent)<\/span>\r\n\r\n<span style=\"font-weight: 400;\">SELECT customer_id, SUM(amount)<\/span>\r\n\r\n<span style=\"font-weight: 400;\">FROM Transactions<\/span>\r\n\r\n<span style=\"font-weight: 400;\">GROUP BY customer_id<\/span>\r\n\r\n<span style=\"font-weight: 400;\">HAVING SUM(amount) &gt; 10000;<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">B\u1ea3ng <\/span><span style=\"font-weight: 400;\">HighValueCustomers<\/span><span style=\"font-weight: 400;\"> s\u1ebd tr\u1edf th\u00e0nh:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>customer_id<\/b><\/td>\n<td><b>total_spent<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">1<\/span><\/td>\n<td><span style=\"font-weight: 400;\">15000<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">3<\/span><\/td>\n<td><span style=\"font-weight: 400;\">12000<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\">Gi\u1ea3i th\u00edch: T\u1eeb b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">Transactions<\/span><\/i><span style=\"font-weight: 400;\">, l\u1ec7nh t\u00ednh t\u1ed5ng s\u1ed1 ti\u1ec1n chi ti\u00eau (<\/span><span style=\"font-weight: 400;\">SUM(amount)<\/span><span style=\"font-weight: 400;\">) c\u1ee7a t\u1eebng kh\u00e1ch h\u00e0ng (customer_id) v\u00e0 ch\u1ec9 gi\u1eef l\u1ea1i nh\u1eefng kh\u00e1ch h\u00e0ng c\u00f3 t\u1ed5ng chi ti\u00eau l\u1edbn h\u01a1n <\/span><span style=\"font-weight: 400;\">10000<\/span><span style=\"font-weight: 400;\"> nh\u1edd m\u1ec7nh \u0111\u1ec1 <\/span><span style=\"font-weight: 400;\">HAVING<\/span><span style=\"font-weight: 400;\">. K\u1ebft qu\u1ea3 l\u00e0 kh\u00e1ch h\u00e0ng 1 v\u1edbi t\u1ed5ng chi ti\u00eau <\/span><span style=\"font-weight: 400;\">15000<\/span><span style=\"font-weight: 400;\"> v\u00e0 kh\u00e1ch h\u00e0ng 3 v\u1edbi t\u1ed5ng chi ti\u00eau <\/span><span style=\"font-weight: 400;\">12000<\/span><span style=\"font-weight: 400;\"> \u0111\u01b0\u1ee3c th\u00eam v\u00e0o b\u1ea3ng <\/span><i><span style=\"font-weight: 400;\">HighValueCustomers<\/span><\/i><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Cau_hoi_thuong_gap_ve_cau_lenh_INSERT_trong_SQL\"><\/span><b>C\u00e2u h\u1ecfi th\u01b0\u1eddng g\u1eb7p v\u1ec1 c\u00e2u l\u1ec7nh INSERT trong SQL<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><b>C\u1ea7n l\u00e0m g\u00ec n\u1ebfu gi\u00e1 tr\u1ecb mu\u1ed1n ch\u00e8n tr\u00f9ng v\u1edbi kh\u00f3a ch\u00ednh?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">N\u1ebfu gi\u00e1 tr\u1ecb mu\u1ed1n ch\u00e8n tr\u00f9ng v\u1edbi kh\u00f3a ch\u00ednh \u0111\u00e3 t\u1ed3n t\u1ea1i, MySQL s\u1ebd b\u00e1o l\u1ed7i do vi ph\u1ea1m r\u00e0ng bu\u1ed9c. \u0110\u1ec3 x\u1eed l\u00fd, b\u1ea1n c\u00f3 th\u1ec3:<\/span><\/p>\n<h4><b>B\u1ecf qua b\u1ea3n ghi tr\u00f9ng l\u1eb7p<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">S\u1eed d\u1ee5ng <\/span><span style=\"font-weight: 400;\">INSERT IGNORE<\/span><span style=\"font-weight: 400;\"> \u0111\u1ec3 MySQL b\u1ecf qua b\u1ea3n ghi g\u00e2y l\u1ed7i. Tuy nhi\u00ean, vi\u1ec7c s\u1eed d\u1ee5ng <\/span><span style=\"font-weight: 400;\">IGNORE<\/span><span style=\"font-weight: 400;\"> kh\u00f4ng \u0111\u01b0\u1ee3c xem l\u00e0 m\u1ed9t gi\u1ea3i ph\u00e1p th\u1ef1c s\u1ef1 v\u00ec b\u1ea3n ghi tr\u00f9ng l\u1eb7p s\u1ebd kh\u00f4ng \u0111\u01b0\u1ee3c ph\u00e1t hi\u1ec7n v\u00e0 kh\u00f4ng \u0111\u01b0\u1ee3c gi\u1ea3i quy\u1ebft. V\u00ed d\u1ee5:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">INSERT IGNORE INTO table_name (id, column1) VALUES (1, 'value1');<\/span><\/pre>\n<h4><b>C\u1eadp nh\u1eadt d\u1eef li\u1ec7u n\u1ebfu tr\u00f9ng l\u1eb7p<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">S\u1eed d\u1ee5ng <\/span><span style=\"font-weight: 400;\">INSERT &#8230; ON DUPLICATE KEY UPDATE<\/span><span style=\"font-weight: 400;\"> \u0111\u1ec3 c\u1eadp nh\u1eadt b\u1ea3n ghi n\u1ebfu kh\u00f3a ch\u00ednh \u0111\u00e3 t\u1ed3n t\u1ea1i. V\u00ed d\u1ee5:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">INSERT INTO table_name (id, column1)\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">VALUES (1, 'value1')\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">ON DUPLICATE KEY UPDATE column1 = 'updated_value';<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Gi\u1ea3i th\u00edch: Khi <\/span><span style=\"font-weight: 400;\">id = 1<\/span><span style=\"font-weight: 400;\"> \u0111\u00e3 t\u1ed3n t\u1ea1i, gi\u00e1 tr\u1ecb c\u1ee7a <\/span><i><span style=\"font-weight: 400;\">column1<\/span><\/i><span style=\"font-weight: 400;\"> s\u1ebd \u0111\u01b0\u1ee3c c\u1eadp nh\u1eadt th\u00e0nh <\/span><i><span style=\"font-weight: 400;\">&#8216;updated_value&#8217;<\/span><\/i><span style=\"font-weight: 400;\">. Ph\u01b0\u01a1ng ph\u00e1p n\u00e0y ph\u00f9 h\u1ee3p trong tr\u01b0\u1eddng h\u1ee3p b\u1ea1n mu\u1ed1n gi\u1eef l\u1ea1i b\u1ea3n ghi c\u0169 nh\u01b0ng c\u1eadp nh\u1eadt m\u1ed9t s\u1ed1 th\u00f4ng tin.<\/span><\/p>\n<blockquote><p><em>\u0110\u1ecdc th\u00eam: <a href=\"https:\/\/itviec.com\/blog\/cau-lenh-update-trong-sql\/\" target=\"_blank\" rel=\"noopener\"><strong>C\u00e2u l\u1ec7nh Update trong SQL: C\u00e1c th\u00e0nh ph\u1ea7n v\u00e0 c\u00e1ch ho\u1ea1t \u0111\u1ed9ng<\/strong><\/a><\/em><\/p><\/blockquote>\n<h4><b>X\u00f3a b\u1ea3n ghi c\u0169 v\u00e0 ch\u00e8n b\u1ea3n ghi m\u1edbi<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">N\u1ebfu b\u1ea1n mu\u1ed1n ho\u00e0n to\u00e0n thay th\u1ebf b\u1ea3n ghi c\u0169 b\u1eb1ng b\u1ea3n ghi m\u1edbi, b\u1ea1n c\u00f3 th\u1ec3 x\u00f3a b\u1ea3n ghi c\u0169 tr\u01b0\u1edbc khi ch\u00e8n b\u1ea3n ghi m\u1edbi.<\/span><\/p>\n<h4><b>S\u1eed d\u1ee5ng <\/b><strong>REPLACE<\/strong><b> \u0111\u1ec3 thay th\u1ebf b\u1ea3n ghi c\u0169<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">Trong MySQL, b\u1ea1n c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng m\u1ec7nh \u0111\u1ec1 <\/span><span style=\"font-weight: 400;\">REPLACE<\/span><span style=\"font-weight: 400;\"> \u0111\u1ec3 thay th\u1ebf b\u1ea3n ghi c\u0169 khi c\u00f3 xung \u0111\u1ed9t v\u1edbi kh\u00f3a ch\u00ednh. L\u1ec7nh n\u00e0y t\u1ef1 \u0111\u1ed9ng x\u00f3a b\u1ea3n ghi c\u0169 v\u00e0 ch\u00e8n b\u1ea3n ghi m\u1edbi v\u00e0o b\u1ea3ng. V\u00ed d\u1ee5:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">REPLACE INTO table_name (id, column1)<\/span>\r\n\r\n<span style=\"font-weight: 400;\">VALUES (1, 'new_value');<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Gi\u1ea3i th\u00edch: Khi <\/span><span style=\"font-weight: 400;\">id = 1<\/span><span style=\"font-weight: 400;\"> \u0111\u00e3 t\u1ed3n t\u1ea1i, MySQL s\u1ebd x\u00f3a b\u1ea3n ghi c\u0169 v\u00e0 th\u00eam b\u1ea3n ghi m\u1edbi v\u1edbi <\/span><span style=\"font-weight: 400;\">id = 1<\/span><span style=\"font-weight: 400;\">. Ph\u01b0\u01a1ng ph\u00e1p n\u00e0y ph\u00f9 h\u1ee3p khi b\u1ea1n c\u1ea7n thay th\u1ebf to\u00e0n b\u1ed9 d\u1eef li\u1ec7u c\u1ee7a b\u1ea3n ghi.<\/span><\/p>\n<h3><b>C\u00f3 th\u1ec3 ch\u00e8n d\u1eef li\u1ec7u m\u00e0 kh\u00f4ng ch\u1ec9 \u0111\u1ecbnh t\u1ea5t c\u1ea3 c\u00e1c c\u1ed9t kh\u00f4ng?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">C\u00f3, b\u1ea1n c\u00f3 th\u1ec3 ch\u1ec9 \u0111\u1ecbnh m\u1ed9t s\u1ed1 c\u1ed9t c\u1ee5 th\u1ec3 trong l\u1ec7nh INSERT, mi\u1ec5n l\u00e0 c\u00e1c c\u1ed9t c\u00f2n l\u1ea1i:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">\u0110\u01b0\u1ee3c thi\u1ebft l\u1eadp gi\u00e1 tr\u1ecb m\u1eb7c \u0111\u1ecbnh (<\/span><span style=\"font-weight: 400;\">DEFAULT<\/span><span style=\"font-weight: 400;\">).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">\u0110\u01b0\u1ee3c ph\u00e9p ch\u1ee9a gi\u00e1 tr\u1ecb <\/span><span style=\"font-weight: 400;\">NULL<\/span><span style=\"font-weight: 400;\">.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Ho\u1eb7c b\u1ea1n c\u00f3 th\u1ec3 kh\u00f4ng c\u1ea7n ch\u1ec9 \u0111\u1ecbnh c\u1ed9t trong c\u00e2u l\u1ec7nh INSERT. Tuy nhi\u00ean \u0111i\u1ec1u n\u00e0y y\u00eau c\u1ea7u c\u00e1c gi\u00e1 tr\u1ecb trong m\u1ec7nh \u0111\u1ec1 VALUES ph\u1ea3i t\u01b0\u01a1ng \u1ee9ng v\u1edbi t\u1ea5t c\u1ea3 c\u1ed9t trong b\u1ea3ng.<\/span><\/p>\n<h3><b>L\u00e0m sao \u0111\u1ec3 ch\u00e8n gi\u00e1 tr\u1ecb m\u1eb7c \u0111\u1ecbnh v\u00e0o c\u1ed9t?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">B\u1ea1n c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng t\u1eeb kh\u00f3a <\/span><span style=\"font-weight: 400;\">DEFAULT<\/span><span style=\"font-weight: 400;\"> \u0111\u1ec3 ch\u00e8n gi\u00e1 tr\u1ecb m\u1eb7c \u0111\u1ecbnh \u0111\u01b0\u1ee3c thi\u1ebft l\u1eadp tr\u01b0\u1edbc cho m\u1ed9t c\u1ed9t. V\u00ed d\u1ee5:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">INSERT INTO Orders (customer_id, product_id, order_date)\u00a0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">VALUES (1, 101, DEFAULT);<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Gi\u1ea3i th\u00edch: c\u1ed9t <\/span><i><span style=\"font-weight: 400;\">order_date<\/span><\/i><span style=\"font-weight: 400;\"> s\u1ebd t\u1ef1 \u0111\u1ed9ng nh\u1eadn gi\u00e1 tr\u1ecb m\u1eb7c \u0111\u1ecbnh \u0111\u01b0\u1ee3c c\u1ea5u h\u00ecnh (nh\u01b0 <\/span><i><span style=\"font-weight: 400;\">CURRENT_DATE<\/span><\/i><span style=\"font-weight: 400;\">). N\u1ebfu kh\u00f4ng ch\u1ec9 \u0111\u1ecbnh, MySQL c\u0169ng t\u1ef1 \u0111\u1ed9ng \u00e1p d\u1ee5ng gi\u00e1 tr\u1ecb m\u1eb7c \u0111\u1ecbnh cho c\u00e1c c\u1ed9t kh\u00f4ng \u0111\u01b0\u1ee3c n\u00eau trong c\u00e2u l\u1ec7nh <\/span><span style=\"font-weight: 400;\">INSERT<\/span><span style=\"font-weight: 400;\">.<\/span><\/p>\n<h3><b>C\u00f3 th\u1ec3 ch\u00e8n d\u1eef li\u1ec7u m\u00e0 kh\u00f4ng ch\u1ec9 \u0111\u1ecbnh t\u1ea5t c\u1ea3 c\u00e1c c\u1ed9t kh\u00f4ng?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">C\u00f3, b\u1ea1n ch\u1ec9 c\u1ea7n n\u00eau c\u00e1c c\u1ed9t c\u1ea7n ch\u00e8n d\u1eef li\u1ec7u trong c\u00e2u l\u1ec7nh <\/span><span style=\"font-weight: 400;\">INSERT<\/span><span style=\"font-weight: 400;\">. C\u00e1c c\u1ed9t kh\u00f4ng \u0111\u01b0\u1ee3c \u0111\u1ec1 c\u1eadp s\u1ebd t\u1ef1 \u0111\u1ed9ng nh\u1eadn gi\u00e1 tr\u1ecb m\u1eb7c \u0111\u1ecbnh ho\u1eb7c <\/span><span style=\"font-weight: 400;\">NULL<\/span><span style=\"font-weight: 400;\"> (n\u1ebfu cho ph\u00e9p).<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">INSERT INTO Orders (customer_id, product_id)<\/span>\r\n\r\n<span style=\"font-weight: 400;\">VALUES (1, 101);<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Gi\u1ea3i th\u00edch: C\u1ed9t kh\u00f4ng \u0111\u01b0\u1ee3c n\u00eau nh\u01b0 <\/span><i><span style=\"font-weight: 400;\">created_at<\/span><\/i><span style=\"font-weight: 400;\"> s\u1ebd t\u1ef1 \u0111\u1ed9ng nh\u1eadn gi\u00e1 tr\u1ecb m\u1eb7c \u0111\u1ecbnh (v\u00ed d\u1ee5: <\/span><i><span style=\"font-weight: 400;\">CURRENT_DATE<\/span><\/i><span style=\"font-weight: 400;\">).<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Tong_ket_cau_lenh_INSERT_trong_SQL\"><\/span><b>T\u1ed5ng k\u1ebft c\u00e2u l\u1ec7nh INSERT trong SQL<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">V\u1ec1 c\u01a1 b\u1ea3n, c\u00e2u l\u1ec7nh INSERT trong SQL<\/span><span style=\"font-weight: 400;\">\u00a0gi\u00fap b\u1ea1n d\u1ec5 d\u00e0ng th\u00eam d\u1eef li\u1ec7u m\u1edbi v\u00e0o b\u1ea3ng v\u00e0 n\u00f3 \u0111\u00f3ng vai tr\u00f2 quan tr\u1ecdng trong vi\u1ec7c duy tr\u00ec v\u00e0 ph\u00e1t tri\u1ec3n h\u1ec7 th\u1ed1ng c\u01a1 s\u1edf d\u1eef li\u1ec7u. Vi\u1ec7c n\u1eafm v\u1eefng c\u00fa ph\u00e1p v\u00e0 c\u00e1c tr\u01b0\u1eddng h\u1ee3p s\u1eed d\u1ee5ng s\u1ebd gi\u00fap b\u1ea1n t\u1ed1i \u01b0u h\u00f3a vi\u1ec7c qu\u1ea3n l\u00fd d\u1eef li\u1ec7u, t\u1eeb ch\u00e8n d\u1eef li\u1ec7u \u0111\u01a1n gi\u1ea3n \u0111\u1ebfn x\u1eed l\u00fd t\u00ecnh hu\u1ed1ng ph\u1ee9c t\u1ea1p.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ITviec hy v\u1ecdng b\u00e0i vi\u1ebft tr\u00ean \u0111\u00e3 cung c\u1ea5p \u0111\u1ee7 th\u00f4ng tin gi\u00fap b\u1ea1n hi\u1ec3u v\u00e0 s\u1eed d\u1ee5ng l\u1ec7nh <\/span><span style=\"font-weight: 400;\">INSERT<\/span><span style=\"font-weight: 400;\"> hi\u1ec7u qu\u1ea3.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>C\u00e2u l\u1ec7nh INSERT trong SQL l\u00e0 m\u1ed9t c\u00f4ng c\u1ee5 thi\u1ebft y\u1ebfu \u0111\u1ec3 th\u00eam d\u1eef li\u1ec7u m\u1edbi v\u00e0o c\u00e1c b\u1ea3ng trong c\u01a1 s\u1edf d\u1eef li\u1ec7u. T\u1eeb vi\u1ec7c ch\u00e8n m\u1ed9t b\u1ea3n ghi \u0111\u01a1n gi\u1ea3n, th\u00eam nhi\u1ec1u b\u1ea3n ghi c\u00f9ng l\u00fac, \u0111\u1ebfn sao ch\u00e9p d\u1eef li\u1ec7u t\u1eeb c\u00e1c b\u1ea3ng kh\u00e1c, l\u1ec7nh n\u00e0y mang l\u1ea1i s\u1ef1 linh ho\u1ea1t v\u00e0 [&hellip;]<\/p>\n","protected":false},"author":209,"featured_media":84369,"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-84364","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.7) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>C\u00e2u l\u1ec7nh INSERT trong SQL: C\u00fa ph\u00e1p v\u00e0 c\u00e1ch ho\u1ea1t \u0111\u1ed9ng - ITviec Blog<\/title>\n<meta name=\"description\" content=\"T\u00ecm hi\u1ec3u c\u00e1ch s\u1eed d\u1ee5ng c\u00e2u l\u1ec7nh INSERT trong SQL. H\u01b0\u1edbng d\u1eabn chi ti\u1ebft t\u1eeb c\u00fa ph\u00e1p, c\u00e1ch ho\u1ea1t \u0111\u1ed9ng \u0111\u1ebfn c\u00e1c v\u00ed d\u1ee5 c\u1ee5 th\u1ec3 v\u00e0 th\u1ef1c t\u1ebf.\" \/>\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-insert-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 INSERT trong SQL: C\u00fa ph\u00e1p v\u00e0 c\u00e1ch ho\u1ea1t \u0111\u1ed9ng\" \/>\n<meta property=\"og:description\" content=\"C\u00e2u l\u1ec7nh INSERT trong SQL l\u00e0 m\u1ed9t c\u00f4ng c\u1ee5 thi\u1ebft y\u1ebfu \u0111\u1ec3 th\u00eam d\u1eef li\u1ec7u m\u1edbi v\u00e0o c\u00e1c b\u1ea3ng trong c\u01a1 s\u1edf d\u1eef li\u1ec7u. T\u1eeb vi\u1ec7c ch\u00e8n m\u1ed9t b\u1ea3n ghi \u0111\u01a1n gi\u1ea3n, th\u00eam nhi\u1ec1u b\u1ea3n\" \/>\n<meta property=\"og:url\" content=\"https:\/\/itviec.com\/blog\/cau-lenh-insert-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-01T15:49:02+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-02-01T15:49:46+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/02\/cau-lenh-insert-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=\"12 ph\u00fat\" \/>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"C\u00e2u l\u1ec7nh INSERT trong SQL: C\u00fa ph\u00e1p v\u00e0 c\u00e1ch ho\u1ea1t \u0111\u1ed9ng - ITviec Blog","description":"T\u00ecm hi\u1ec3u c\u00e1ch s\u1eed d\u1ee5ng c\u00e2u l\u1ec7nh INSERT trong SQL. H\u01b0\u1edbng d\u1eabn chi ti\u1ebft t\u1eeb c\u00fa ph\u00e1p, c\u00e1ch ho\u1ea1t \u0111\u1ed9ng \u0111\u1ebfn c\u00e1c v\u00ed d\u1ee5 c\u1ee5 th\u1ec3 v\u00e0 th\u1ef1c t\u1ebf.","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-insert-trong-sql\/","og_locale":"vi_VN","og_type":"article","og_title":"C\u00e2u l\u1ec7nh INSERT trong SQL: C\u00fa ph\u00e1p v\u00e0 c\u00e1ch ho\u1ea1t \u0111\u1ed9ng","og_description":"C\u00e2u l\u1ec7nh INSERT trong SQL l\u00e0 m\u1ed9t c\u00f4ng c\u1ee5 thi\u1ebft y\u1ebfu \u0111\u1ec3 th\u00eam d\u1eef li\u1ec7u m\u1edbi v\u00e0o c\u00e1c b\u1ea3ng trong c\u01a1 s\u1edf d\u1eef li\u1ec7u. T\u1eeb vi\u1ec7c ch\u00e8n m\u1ed9t b\u1ea3n ghi \u0111\u01a1n gi\u1ea3n, th\u00eam nhi\u1ec1u b\u1ea3n","og_url":"https:\/\/itviec.com\/blog\/cau-lenh-insert-trong-sql\/","og_site_name":"ITviec Blog","article_publisher":"https:\/\/www.facebook.com\/ITviec","article_published_time":"2025-02-01T15:49:02+00:00","article_modified_time":"2025-02-01T15:49:46+00:00","og_image":[{"width":1500,"height":790,"url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/02\/cau-lenh-insert-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":"12 ph\u00fat"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/itviec.com\/blog\/cau-lenh-insert-trong-sql\/#article","isPartOf":{"@id":"https:\/\/itviec.com\/blog\/cau-lenh-insert-trong-sql\/"},"author":{"name":"M\u1ef9 Duy\u00ean","@id":"https:\/\/itviec.com\/blog\/#\/schema\/person\/73733c0725c7e39e696a896bd1abe2d7"},"headline":"C\u00e2u l\u1ec7nh INSERT trong SQL: C\u00fa ph\u00e1p v\u00e0 c\u00e1ch ho\u1ea1t \u0111\u1ed9ng","datePublished":"2025-02-01T15:49:02+00:00","dateModified":"2025-02-01T15:49:46+00:00","mainEntityOfPage":{"@id":"https:\/\/itviec.com\/blog\/cau-lenh-insert-trong-sql\/"},"wordCount":3052,"publisher":{"@id":"https:\/\/itviec.com\/blog\/#organization"},"image":{"@id":"https:\/\/itviec.com\/blog\/cau-lenh-insert-trong-sql\/#primaryimage"},"thumbnailUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/02\/cau-lenh-insert-trong-sql-vippro.jpeg","articleSection":["Chuy\u00ean m\u00f4n IT"],"inLanguage":"vi"},{"@type":"WebPage","@id":"https:\/\/itviec.com\/blog\/cau-lenh-insert-trong-sql\/","url":"https:\/\/itviec.com\/blog\/cau-lenh-insert-trong-sql\/","name":"C\u00e2u l\u1ec7nh INSERT trong SQL: C\u00fa ph\u00e1p v\u00e0 c\u00e1ch ho\u1ea1t \u0111\u1ed9ng - ITviec Blog","isPartOf":{"@id":"https:\/\/itviec.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/itviec.com\/blog\/cau-lenh-insert-trong-sql\/#primaryimage"},"image":{"@id":"https:\/\/itviec.com\/blog\/cau-lenh-insert-trong-sql\/#primaryimage"},"thumbnailUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/02\/cau-lenh-insert-trong-sql-vippro.jpeg","datePublished":"2025-02-01T15:49:02+00:00","dateModified":"2025-02-01T15:49:46+00:00","description":"T\u00ecm hi\u1ec3u c\u00e1ch s\u1eed d\u1ee5ng c\u00e2u l\u1ec7nh INSERT trong SQL. H\u01b0\u1edbng d\u1eabn chi ti\u1ebft t\u1eeb c\u00fa ph\u00e1p, c\u00e1ch ho\u1ea1t \u0111\u1ed9ng \u0111\u1ebfn c\u00e1c v\u00ed d\u1ee5 c\u1ee5 th\u1ec3 v\u00e0 th\u1ef1c t\u1ebf.","breadcrumb":{"@id":"https:\/\/itviec.com\/blog\/cau-lenh-insert-trong-sql\/#breadcrumb"},"inLanguage":"vi","potentialAction":[{"@type":"ReadAction","target":["https:\/\/itviec.com\/blog\/cau-lenh-insert-trong-sql\/"]}]},{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/itviec.com\/blog\/cau-lenh-insert-trong-sql\/#primaryimage","url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/02\/cau-lenh-insert-trong-sql-vippro.jpeg","contentUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/02\/cau-lenh-insert-trong-sql-vippro.jpeg","width":1500,"height":790,"caption":"c\u00e2u l\u1ec7nh insert trong sql"},{"@type":"BreadcrumbList","@id":"https:\/\/itviec.com\/blog\/cau-lenh-insert-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 INSERT trong SQL: C\u00fa ph\u00e1p v\u00e0 c\u00e1ch ho\u1ea1t \u0111\u1ed9ng"}]},{"@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\/84364","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=84364"}],"version-history":[{"count":0,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts\/84364\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/media\/84369"}],"wp:attachment":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/media?parent=84364"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/categories?post=84364"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/tags?post=84364"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}