{"id":179612,"date":"2024-11-09T03:16:28","date_gmt":"2024-11-08T19:16:28","guid":{"rendered":"https:\/\/server.hk\/cnblog\/179612\/"},"modified":"2024-11-09T03:16:28","modified_gmt":"2024-11-08T19:16:28","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8-mssql-%e4%b8%ad%e9%80%b2%e8%a1%8c-insert-%e6%93%8d%e4%bd%9c%ef%bc%9f%ef%bc%88insert-mssql%ef%bc%89","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/179612\/","title":{"rendered":"\u5982\u4f55\u5728 MSSQL \u4e2d\u9032\u884c INSERT \u64cd\u4f5c\uff1f\uff08insert mssql\uff09"},"content":{"rendered":"<h1 id=\"%e5%a6%82%e4%bd%95%e5%9c%a8-mssql-%e4%b8%ad%e9%80%b2%e8%a1%8c-insert-%e6%93%8d%e4%bd%9c%ef%bc%9f%ef%bc%88insert-mssql%ef%bc%89-btrJHpOwNM\">\u5982\u4f55\u5728 MSSQL \u4e2d\u9032\u884c INSERT \u64cd\u4f5c\uff1f\uff08insert mssql\uff09<\/h1>\n<p>\u5728\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\u4e2d\uff0cINSERT \u64cd\u4f5c\u662f\u7528\u4f86\u5c07\u65b0\u6578\u64da\u63d2\u5165\u5230\u8868\u4e2d\u7684\u57fa\u672c\u529f\u80fd\u4e4b\u4e00\u3002\u5c0d\u65bc\u4f7f\u7528 Microsoft SQL Server\uff08MSSQL\uff09\u7684\u958b\u767c\u8005\u4f86\u8aaa\uff0c\u4e86\u89e3\u5982\u4f55\u6b63\u78ba\u5730\u57f7\u884c INSERT \u64cd\u4f5c\u662f\u81f3\u95dc\u91cd\u8981\u7684\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e MSSQL \u4e2d\u7684 INSERT \u64cd\u4f5c\uff0c\u5305\u62ec\u57fa\u672c\u8a9e\u6cd5\u3001\u793a\u4f8b\u4ee5\u53ca\u4e00\u4e9b\u6700\u4f73\u5be6\u8e10\u3002<\/p>\n<h2 id=\"%e5%9f%ba%e6%9c%ac%e8%aa%9e%e6%b3%95-btrJHpOwNM\">\u57fa\u672c\u8a9e\u6cd5<\/h2>\n<p>MSSQL \u4e2d\u7684 INSERT \u8a9e\u53e5\u6709\u5e7e\u7a2e\u4e0d\u540c\u7684\u5f62\u5f0f\uff0c\u6700\u5e38\u898b\u7684\u8a9e\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code>INSERT INTO \u8868\u540d (\u6b04\u4f4d1, \u6b04\u4f4d2, \u6b04\u4f4d3, ...)\nVALUES (\u503c1, \u503c2, \u503c3, ...);<\/code><\/pre>\n<p>\u5728\u9019\u88e1\uff0c<strong>\u8868\u540d<\/strong> \u662f\u4f60\u8981\u63d2\u5165\u6578\u64da\u7684\u76ee\u6a19\u8868\uff0c\u800c <strong>\u6b04\u4f4d<\/strong> \u548c <strong>\u503c<\/strong> \u5247\u5206\u5225\u4ee3\u8868\u8981\u63d2\u5165\u7684\u5217\u548c\u5c0d\u61c9\u7684\u6578\u64da\u3002<\/p>\n<h2 id=\"%e7%a4%ba%e4%be%8b-btrJHpOwNM\">\u793a\u4f8b<\/h2>\n<p>\u5047\u8a2d\u6211\u5011\u6709\u4e00\u500b\u540d\u70ba <strong>Customers<\/strong> \u7684\u8868\uff0c\u7d50\u69cb\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li><strong>CustomerID<\/strong> (\u6574\u6578\u578b\uff0c\u81ea\u52d5\u589e\u91cf)<\/li>\n<li><strong>FirstName<\/strong> (\u5b57\u4e32\u578b)<\/li>\n<li><strong>LastName<\/strong> (\u5b57\u4e32\u578b)<\/li>\n<li><strong>Email<\/strong> (\u5b57\u4e32\u578b)<\/li>\n<\/ul>\n<p>\u8981\u5411\u9019\u500b\u8868\u4e2d\u63d2\u5165\u4e00\u689d\u65b0\u8a18\u9304\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b SQL \u8a9e\u53e5\uff1a<\/p>\n<pre><code>INSERT INTO Customers (FirstName, LastName, Email)\nVALUES ('John', 'Doe', 'john.doe@example.com');<\/code><\/pre>\n<p>\u9019\u689d\u8a9e\u53e5\u5c07\u6703\u5728 <strong>Customers<\/strong> \u8868\u4e2d\u63d2\u5165\u4e00\u500b\u540d\u70ba John Doe \u7684\u65b0\u5ba2\u6236\uff0c\u4e26\u4e14\u5176\u96fb\u5b50\u90f5\u4ef6\u5730\u5740\u70ba john.doe@example.com\u3002<\/p>\n<h2 id=\"%e6%8f%92%e5%85%a5%e5%a4%9a%e6%a2%9d%e8%a8%98%e9%8c%84-btrJHpOwNM\">\u63d2\u5165\u591a\u689d\u8a18\u9304<\/h2>\n<p>MSSQL \u4e5f\u652f\u6301\u4e00\u6b21\u6027\u63d2\u5165\u591a\u689d\u8a18\u9304\u3002\u9019\u53ef\u4ee5\u901a\u904e\u5728 VALUES \u5b50\u53e5\u4e2d\u4f7f\u7528\u9017\u865f\u5206\u9694\u7684\u591a\u7d44\u503c\u4f86\u5be6\u73fe\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code>INSERT INTO Customers (FirstName, LastName, Email)\nVALUES \n('Jane', 'Smith', 'jane.smith@example.com'),\n('Alice', 'Johnson', 'alice.johnson@example.com');<\/code><\/pre>\n<p>\u9019\u6a23\u7684\u8a9e\u53e5\u5c07\u6703\u540c\u6642\u63d2\u5165\u5169\u689d\u65b0\u8a18\u9304\u3002<\/p>\n<h2 id=\"%e4%bd%bf%e7%94%a8-select-%e8%aa%9e%e5%8f%a5%e6%8f%92%e5%85%a5%e6%95%b8%e6%93%9a-btrJHpOwNM\">\u4f7f\u7528 SELECT \u8a9e\u53e5\u63d2\u5165\u6578\u64da<\/h2>\n<p>\u9664\u4e86\u76f4\u63a5\u63d2\u5165\u6578\u64da\u5916\uff0cMSSQL \u9084\u5141\u8a31\u4f7f\u7528 SELECT \u8a9e\u53e5\u5f9e\u5176\u4ed6\u8868\u4e2d\u9078\u64c7\u6578\u64da\u4e26\u63d2\u5165\u5230\u76ee\u6a19\u8868\u4e2d\u3002\u9019\u6a23\u7684\u8a9e\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code>INSERT INTO \u76ee\u6a19\u8868 (\u6b04\u4f4d1, \u6b04\u4f4d2)\nSELECT \u6b04\u4f4dA, \u6b04\u4f4dB\nFROM \u6e90\u8868\nWHERE \u689d\u4ef6;<\/code><\/pre>\n<p>\u4f8b\u5982\uff0c\u5982\u679c\u6211\u5011\u6709\u4e00\u500b\u540d\u70ba <strong>ArchivedCustomers<\/strong> \u7684\u8868\uff0c\u4e26\u5e0c\u671b\u5c07\u6240\u6709\u96fb\u5b50\u90f5\u4ef6\u4ee5 &#8220;example.com&#8221; \u7d50\u5c3e\u7684\u5ba2\u6236\u63d2\u5165\u5230 <strong>Customers<\/strong> \u8868\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8a9e\u53e5\uff1a<\/p>\n<pre><code>INSERT INTO Customers (FirstName, LastName, Email)\nSELECT FirstName, LastName, Email\nFROM ArchivedCustomers\nWHERE Email LIKE '%@example.com';<\/code><\/pre>\n<h2 id=\"%e6%9c%80%e4%bd%b3%e5%af%a6%e8%b8%90-btrJHpOwNM\">\u6700\u4f73\u5be6\u8e10<\/h2>\n<ul>\n<li><strong>\u4f7f\u7528\u4e8b\u52d9\uff1a<\/strong>\u5728\u57f7\u884c INSERT \u64cd\u4f5c\u6642\uff0c\u5efa\u8b70\u4f7f\u7528\u4e8b\u52d9\u4f86\u78ba\u4fdd\u6578\u64da\u7684\u4e00\u81f4\u6027\u548c\u5b8c\u6574\u6027\u3002<\/li>\n<li><strong>\u6aa2\u67e5\u7d04\u675f\uff1a<\/strong>\u5728\u63d2\u5165\u6578\u64da\u4e4b\u524d\uff0c\u61c9\u6aa2\u67e5\u8868\u7684\u7d04\u675f\u689d\u4ef6\uff0c\u4ee5\u907f\u514d\u9055\u53cd\u4e3b\u9375\u3001\u5916\u9375\u6216\u552f\u4e00\u6027\u7d04\u675f\u3002<\/li>\n<li><strong>\u907f\u514d SQL \u6ce8\u5165\uff1a<\/strong>\u5728\u8655\u7406\u7528\u6236\u8f38\u5165\u6642\uff0c\u61c9\u4f7f\u7528\u53c3\u6578\u5316\u67e5\u8a62\u4f86\u9632\u6b62 SQL \u6ce8\u5165\u653b\u64ca\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-btrJHpOwNM\">\u7e3d\u7d50<\/h2>\n<p>\u5728 MSSQL \u4e2d\u9032\u884c INSERT \u64cd\u4f5c\u662f\u6578\u64da\u5eab\u7ba1\u7406\u7684\u57fa\u672c\u6280\u80fd\u4e4b\u4e00\u3002\u901a\u904e\u638c\u63e1\u57fa\u672c\u8a9e\u6cd5\u3001\u793a\u4f8b\u548c\u6700\u4f73\u5be6\u8e10\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u6709\u6548\u5730\u7ba1\u7406\u6578\u64da\u3002\u7121\u8ad6\u662f\u55ae\u689d\u9084\u662f\u591a\u689d\u8a18\u9304\u7684\u63d2\u5165\uff0c\u6b63\u78ba\u7684\u64cd\u4f5c\u90fd\u80fd\u78ba\u4fdd\u6578\u64da\u7684\u5b8c\u6574\u6027\u548c\u4e00\u81f4\u6027\u3002\u5982\u679c\u60a8\u9700\u8981\u66f4\u591a\u6709\u95dc <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u548c\u6578\u64da\u5eab\u7ba1\u7406\u7684\u8cc7\u8a0a\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3\u5982\u4f55\u5728 MSSQL \u4e2d\u57f7\u884c INSERT \u64cd\u4f5c\uff0c\u5b78\u7fd2\u57fa\u672c\u8a9e\u6cd5\u548c\u7bc4\u4f8b\uff0c\u8f15\u9b06\u5c07\u6578\u64da\u63d2\u5165\u8cc7\u6599\u8868\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-179612","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/179612","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=179612"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/179612\/revisions"}],"predecessor-version":[{"id":179613,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/179612\/revisions\/179613"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=179612"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=179612"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=179612"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}