{"id":1062,"date":"2009-09-15T00:17:03","date_gmt":"2009-09-14T16:17:03","guid":{"rendered":"http:\/\/jason695.why3s.tw\/wordpress\/?p=1062"},"modified":"2015-03-08T18:48:00","modified_gmt":"2015-03-08T10:48:00","slug":"%e8%bd%89%e8%b2%bc%e5%b0%87%e8%b3%87%e6%96%99%e5%ba%ab%e8%a1%a8%e6%a0%bc%e4%b8%ad%e7%9a%84%e8%b3%87%e6%96%99%e4%bb%a5-insert-into-%e6%8c%87%e4%bb%a4%e7%9a%84%e6%96%b9%e5%bc%8f%e5%8c%af%e5%87%ba","status":"publish","type":"post","link":"https:\/\/jason695.why3s.tw\/wordpress\/2009\/09\/15\/%e8%bd%89%e8%b2%bc%e5%b0%87%e8%b3%87%e6%96%99%e5%ba%ab%e8%a1%a8%e6%a0%bc%e4%b8%ad%e7%9a%84%e8%b3%87%e6%96%99%e4%bb%a5-insert-into-%e6%8c%87%e4%bb%a4%e7%9a%84%e6%96%b9%e5%bc%8f%e5%8c%af%e5%87%ba\/","title":{"rendered":"[\u8f49\u8cbc]\u5c07\u8cc7\u6599\u5eab\u8868\u683c\u4e2d\u7684\u8cc7\u6599\u4ee5 INSERT INTO \u6307\u4ee4\u7684\u65b9\u5f0f\u532f\u51fa"},"content":{"rendered":"<p>\u539f\u6587\u7db2\u5740\uff1a<a href=\"http:\/\/twg.idv.tw\/dv_rss_xhtml_155_85551_2.html\">http:\/\/twg.idv.tw\/dv_rss_xhtml_155_85551_2.html<\/a><\/p>\n<p>\u901a\u5e38\u6211\u5011\u5f9e SQL Server \u532f\u51fa\u8cc7\u6599\u5230\u53e6\u4e00\u53f0\u4e3b\u6a5f\u5927\u81f4\u4e0a\u6709\u5e7e\u7a2e\u65b9\u5f0f\uff1a<\/p>\n<ol>\n<li>\u4f7f\u7528 bcp.exe \u532f\u51fa\u6210\u7d14\u6587\u5b57\u683c\u5f0f\uff0c\u5728\u5230\u53e6\u4e00\u53f0\u4e3b\u6a5f\u7528 bcp.exe \u532f\u5165\u8cc7\u6599<\/li>\n<li>\u4f7f\u7528 DTS (Data Transformation Services) \u6216 SSIS (SQL Server Integration Services) \u5c07\u8cc7\u6599\u5c01\u88dd\u6210\u6a94\u6848\uff0c\u4e26\u5e36\u5230\u53e6\u4e00\u53f0 Server \u532f\u5165\u8cc7\u6599\u3002<\/li>\n<li>\u5099\u4efd\u6574\u500b\u8cc7\u6599\u5eab\uff0c\u5c07\u5099\u4efd\u6a94(*.bak)\u5e36\u5230\u53e6\u4e00\u53f0\u4e3b\u6a5f\u9084\u539f\u8cc7\u6599<\/li>\n<li>\u5378\u8f09(Detach)\u8cc7\u6599\u5eab\uff0c\u5c07\u8cc7\u6599\u5eab\u6a94(*.mdf \u8207 *.ldf)\u5e36\u5230\u53e6\u4e00\u53f0\u4e3b\u6a5f\u9644\u52a0(Attach)\u8cc7\u6599\u5eab<\/li>\n<\/ol>\n<p>\u6211\u4ee5\u524d\u5e38\u7528 MySQL \u8cc7\u6599\u5eab\uff0c\u532f\u51fa\u8cc7\u6599\u5eab\u7684\u6642\u5019\u90fd\u662f DDL ( CREATE TABLE, &#8230; ), DML (INSERT INTO, &#8230; ) \u7684\u683c\u5f0f\u5132\u5b58\uff0c\u8981\u79fb\u8f49\u8cc7\u6599\u5230\u5176\u4ed6\u4e3b\u6a5f\u90fd\u5f88\u65b9\u4fbf\u3002\u4f46\u6539\u7528 SQL Server \u6642\u9019\u4e9b\u6771\u897f\u90fd\u4e0d\u898b\u4e86\uff0c\u8b93\u6211\u56f0\u64fe\u4e86\u597d\u4e45\uff0c\u6709\u6642\u5f8c\u70ba\u4e86\u8f49\u79fb\u4e00\u4e9b\u8cc7\u6599\u90fd\u8981\u82b1\u8cbb\u5f88\u5927\u7684\u529b\u6c23\u5c07\u8cc7\u6599\u8f49\u79fb\u5230\u9060\u7aef\u7684\u4e3b\u6a5f\uff0c\u56e0\u70ba\u6709\u4e9b\u9060\u7aef\u7684 SQL Server \u662f\u7121\u6cd5\u76f4\u63a5\u7528 Management Studio \u9060\u7aef\u9023\u63a5\uff0c\u53ea\u80fd\u7528 Web \u4ecb\u9762\u7ba1\u7406\u6642\uff0c\u5c31\u5f88\u5f88\u9ebb\u7169\u3002<\/p>\n<p>\u4f46\u6211\u4eca\u5929\u5728<a title=\"\u9023\u7d50\u81f3http:\/\/vyaskn.tripod.com\/code.htm#inserts\" href=\"http:\/\/twg.idv.tw\/PriveLink.asp?s=****vyaskn.tripod.com\/code.htm#inserts\" target=\"_blank\">\u9019\u88e1<\/a>\u767c\u73fe\u4e00\u500b\u795e\u5947\u7684\u9810\u5132\u7a0b\u5e8f(Stored Procedure)\uff0c\u4f5c\u8005\u662f\u4e00\u4f4d\u53eb\u505a <a title=\"\u9023\u7d50\u81f3http:\/\/vyaskn.tripod.com\/index.htm\" href=\"http:\/\/twg.idv.tw\/PriveLink.asp?s=****vyaskn.tripod.com\/index.htm\" target=\"_blank\">Narayana Vyas Kondreddi<\/a> \u7684\u4ec1\u5144\uff0c\u5149\u770b\u540d\u5b57\u5be6\u5728\u770b\u4e0d\u51fa\u662f\u54ea\u4e00\u570b\u4eba :-p<\/p>\n<p>\u4ed6\u5beb\u7684 T-SQL \u53ef\u4ee5\u5c07\u8868\u683c\u4e2d\u7684\u8cc7\u6599\u5168\u90e8\u90fd\u8f49\u6210 INSERT INTO \u7684\u5f62\u5f0f\uff0c\u65b9\u4fbf\u4f60\u5c07\u8cc7\u6599\u5e36\u5230\u53e6\u4e00\u53f0\u4e3b\u6a5f\uff0c\u53ea\u8981\u57f7\u884c INSERT INTO \u6307\u4ee4\u5c31\u53ef\u4ee5\u5c07\u8cc7\u6599\u65b0\u589e\u5230\u53e6\u4e00\u53f0\u4e3b\u6a5f\u4e86\u3002<\/p>\n<p>\u9019\u500b\u9810\u5132\u7a0b\u5e8f\u7684\u512a\u9ede\u6709\uff1a<\/p>\n<ul>\n<li>Data from both tables and views can be scripted<\/li>\n<li>No CURSORs are used<\/li>\n<li>Table names and column names with spaces are handled<\/li>\n<li>All datatypes are handled except images, large text and binary columns with more than 4 bytes<\/li>\n<li>NULLs are gracefully handled<\/li>\n<li>Timestamp columns are handled<\/li>\n<li>Identity columns are handled<\/li>\n<li>Very flexible and configurable<\/li>\n<li>Non-dbo owned tables are handled<\/li>\n<li>Computed columns are handled<\/li>\n<li>You can filter the rows for which you want to generate INSERTs<\/li>\n<\/ul>\n<p>\u4e0b\u8f09 Stored Procedure\uff1a<\/p>\n<ul>\n<li><a title=\"\u9023\u7d50\u81f3http:\/\/vyaskn.tripod.com\/code\/generate_inserts.txt\" href=\"http:\/\/twg.idv.tw\/PriveLink.asp?s=****vyaskn.tripod.com\/code\/generate_inserts.txt\" target=\"_blank\">\u4e0b\u8f09 SQL Server 2000 \u7684\u7248\u672c<\/a><\/li>\n<li><a title=\"\u9023\u7d50\u81f3http:\/\/vyaskn.tripod.com\/code\/generate_inserts_2005.txt\" href=\"http:\/\/twg.idv.tw\/PriveLink.asp?s=****vyaskn.tripod.com\/code\/generate_inserts_2005.txt\" target=\"_blank\">\u4e0b\u8f09 SQL Server 2005 \u7684\u7248\u672c<\/a><\/li>\n<\/ul>\n<p>\u5728<a title=\"\u9023\u7d50\u81f3http:\/\/vyaskn.tripod.com\/code.htm#inserts\" href=\"http:\/\/twg.idv.tw\/PriveLink.asp?s=****vyaskn.tripod.com\/code.htm#inserts\" target=\"_blank\">\u539f\u4f5c\u8005\u7684\u7db2\u7ad9<\/a>\u6709 14 \u500b\u4f7f\u7528\u8aaa\u660e\u7bc4\u4f8b(Usage Example)\uff0c\u5404\u4f4d\u53ef\u4ee5\u4e0a\u53bb\u770b\u770b\u3002\u57f7\u884c\u5b8c\u4e0b\u8f09\u7684 T-SQL Script \u4e4b\u5f8c\u6703\u5728 master \u8cc7\u6599\u5eab\u4e2d\u65b0\u589e\u4e00\u500b dbo.sp_generate_inserts \u9810\u5132\u7a0b\u5e8f\u7269\u4ef6\uff0c\u5982\u4e0b\u5716\u793a\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"border-width: 0px;\" src=\"http:\/\/blog.miniasp.com\/image.axd?picture=WindowsLiveWriter\/INSERTINTO_14B58\/image_3.png\" border=\"0\" alt=\"\u57f7\u884c\u5b8c\u4e0b\u8f09\u7684 T-SQL Script=\" width=\"473\" height=\"615\" \/><\/p>\n<p>\u4e0d\u904e\u7f3a\u9ede\u662f\u9019\u500b\u65b9\u6cd5\u6c92\u8fa6\u6cd5\u9069\u7528\u65bc\u6709\u6587\u5b57\u6b04\u4f4d\u5167\u5bb9\u8d85\u904e 8KB \u7684\u8cc7\u6599\uff0c\u56e0\u70ba\u8f38\u51fa\u7684\u7d50\u679c\u662f\u986f\u793a\u5728 SSMS ( SQL Server Management Studio ) \u4e2d\uff0c\u8f38\u51fa\u7684\u6b04\u4f4d\u9577\u5ea6\u662f\u6709\u9650\u5236\u7684\u3002<\/p>\n<p>\u53e6\u5916\uff0c\u9019\u500b\u9810\u5132\u7a0b\u5e8f\u6211\u6709\u767c\u73fe\u4e00\u500b\u5c0f\u554f\u984c\uff0c\u5c31\u662f\u7576\u57f7\u884c\u5b8c\u7562\u5f8c\uff0c\u532f\u51fa\u7684\u8cc7\u6599\u4e2d\u5982\u679c\u5167\u5bb9\u4e2d\u6709\u300c\u65b7\u884c\u7b26\u865f\u300d\u7684\u8a71\uff0c\u5168\u90e8\u90fd\u6703\u88ab\u7f6e\u63db\u6210\u300c\u7a7a\u767d\u300d\u5b57\u5143\uff0c\u5c0e\u81f4\u532f\u5165\u7684\u6642\u5019\u6240\u6709\u65b7\u884c\u5b57\u5143\u90fd\u6703\u88ab\u63db\u6210\u7a7a\u767d\u7b26\u865f\uff0c\u8cc7\u6599\u5c31\u88ab\u7834\u58de\u6389\u4e86\u3002<\/p>\n<p>\u6211\u500b\u4eba\u82b1\u4e86 2 \u500b\u5c0f\u6642\u5c07\u9019\u500b Script \u7814\u7a76\u904e\u4e00\u904d\u4e26\u5c07\u554f\u984c\u7d66\u4fee\u6b63\u4e86\uff08\u53ea\u6539\u4e86\u5169\u884c\uff09\uff0c\u7528 T-SQL \u7522\u751f T-SQL \u7684\u7a0b\u5f0f\u78bc\u771f\u7684\u6703\u8b93\u4eba\u773c\u82b1\u64a9\u4e82\uff0c\u4e00\u5927\u5806\u55ae\u5f15\u865f Quote \u4f86 Quote \u53bb\u7684\uff0c\u4f60\u81ea\u5df1\u770b\u7a0b\u5f0f\u78bc\u5c31\u77e5\u9053\u4e86\uff0c\u6211\u5c07\u66f4\u65b0\u904e\u7684 T-SQL Script \u653e\u5728\u4ee5\u4e0b\u6a94\u6848\u4e2d\uff0c\u6211\u53ea\u6709\u6539\u5beb SQL 2005 \u7684\u7248\u672c\u800c\u5df2\uff1a<\/p>\n<ul>\n<li><a title=\"\u9023\u7d50\u81f3http:\/\/blog.miniasp.com\/file.axd?file=sp_generate_inserts_SQL2005_Will_Fixed.sql\" href=\"http:\/\/twg.idv.tw\/PriveLink.asp?s=****blog.miniasp.com\/file.axd%5C%5C%5C%5Cfile=sp_generate_inserts_SQL2005_Will_Fixed.sql\" target=\"_blank\">\u4e0b\u8f09 SQL Server 2005 \u7684\u7248\uff08Will \u4fee\u6b63\u65b7\u884c\u5b57\u5143\u88ab\u5403\u6389\u7684\u554f\u984c\uff09<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u539f\u6587\u7db2\u5740\uff1ahttp:\/\/twg.idv.tw\/dv_rss_xhtml_155_85551_2.html \u901a\u5e38 &hellip; <a href=\"https:\/\/jason695.why3s.tw\/wordpress\/2009\/09\/15\/%e8%bd%89%e8%b2%bc%e5%b0%87%e8%b3%87%e6%96%99%e5%ba%ab%e8%a1%a8%e6%a0%bc%e4%b8%ad%e7%9a%84%e8%b3%87%e6%96%99%e4%bb%a5-insert-into-%e6%8c%87%e4%bb%a4%e7%9a%84%e6%96%b9%e5%bc%8f%e5%8c%af%e5%87%ba\/\" class=\"more-link\">\u95b1\u8b80\u5168\u6587 <span class=\"screen-reader-text\">[\u8f49\u8cbc]\u5c07\u8cc7\u6599\u5eab\u8868\u683c\u4e2d\u7684\u8cc7\u6599\u4ee5 INSERT INTO \u6307\u4ee4\u7684\u65b9\u5f0f\u532f\u51fa<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[47],"tags":[],"class_list":["post-1062","post","type-post","status-publish","format-standard","hentry","category-sql-server","no-featured-image"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/posts\/1062","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/comments?post=1062"}],"version-history":[{"count":0,"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/posts\/1062\/revisions"}],"wp:attachment":[{"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/media?parent=1062"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/categories?post=1062"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/tags?post=1062"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}