{"id":6256,"date":"2024-11-14T11:17:18","date_gmt":"2024-11-14T03:17:18","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6256\/"},"modified":"2024-11-14T11:17:18","modified_gmt":"2024-11-14T03:17:18","slug":"sql%e6%80%8e%e6%a0%b7%e5%af%bc%e5%85%a5%e6%95%b0%e6%8d%ae%e5%ba%93","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6256\/","title":{"rendered":"sql\u600e\u6837\u5bfc\u5165\u6570\u636e\u5e93"},"content":{"rendered":"<blockquote><p>\n  \u5728 sql \u4e2d\uff0c\u6570\u636e\u5bfc\u5165\u53ef\u4ee5\u901a\u8fc7\u4e24\u79cd\u65b9\u6cd5\u5b9e\u73b0\uff1ainsert \u8bed\u53e5\uff1a\u9010\u884c\u63d2\u5165\u6570\u636e\uff0c\u8bed\u6cd5\u4e3a insert into table_name (column1, &#8230;) values (value1, &#8230;)\u3002bulk insert\uff1a\u4ece\u6587\u4ef6\u6216\u6570\u636e\u5e93\u5feb\u901f\u6279\u91cf\u5bfc\u5165\u6570\u636e\uff0c\u8bed\u6cd5\u4e3a bulk insert table_name from &#8216;file_path&#8217; with (fieldterminator = &#8216;,&#8217;, rowterminator = &#8216; &#8216;, firstrow = 1)\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/17\/2024061710333632438.jpg\" class=\"aligncenter\" title=\"sql\u600e\u6837\u5bfc\u5165\u6570\u636e\u5e93\u63d2\u56fe\" alt=\"sql\u600e\u6837\u5bfc\u5165\u6570\u636e\u5e93\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5c06\u6570\u636e\u5bfc\u5165\u6570\u636e\u5e93<\/strong><\/p>\n<p>\u5bfc\u5165\u6570\u636e\u662f\u5c06\u5916\u90e8\u6570\u636e\u52a0\u8f7d\u5230\u6570\u636e\u5e93\u4e2d\u7684\u8fc7\u7a0b\uff0c\u53ef\u4ee5\u4e3a\u5206\u6790\u3001\u5904\u7406\u6216\u5b58\u50a8\u76ee\u7684\u63d0\u4f9b\u6570\u636e\u3002\u5728 SQL \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u65b9\u6cd5\u6765\u5bfc\u5165\u6570\u636e\uff0c\u4e0b\u9762\u6211\u4eec\u5c06\u4ecb\u7ecd\u6700\u5e38\u7528\u7684\u4e24\u79cd\u65b9\u6cd5\uff1a<\/p>\n<p><strong>INSERT \u8bed\u53e5<\/strong><\/p>\n<p>INSERT \u8bed\u53e5\u5141\u8bb8\u60a8\u5c06\u5355\u4e2a\u6216\u591a\u4e2a\u8bb0\u5f55\u63d2\u5165\u8868\u4e2d\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, ...);<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4f8b\u5982\uff0c\u4ee5\u4e0b\u8bed\u53e5\u5c06\u4e24\u6761\u8bb0\u5f55\u63d2\u5165\u540d\u4e3a customers \u7684\u8868\u4e2d\uff1a<\/p>\n<pre>INSERT INTO customers (name, email, address) VALUES ('John Doe', 'john.doe@example.com', '123 Main Street');\nINSERT INTO customers (name, email, address) VALUES ('Jane Doe', 'jane.doe@example.com', '456 Elm Street');<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>BULK INSERT<\/strong><\/p>\n<p>BULK INSERT \u662f\u5c06\u5927\u91cf\u6570\u636e\uff08\u901a\u5e38\u662f\u4ece\u6587\u4ef6\u6216\u5176\u4ed6\u6570\u636e\u5e93\uff09\u5feb\u901f\u5bfc\u5165\u5230\u8868\u4e2d\u7684\u4e00\u79cd\u66f4\u6709\u6548\u7684\u65b9\u6cd5\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>BULK INSERT table_name FROM 'file_path' WITH (\n  FIELDTERMINATOR = ',',\n  ROWTERMINATOR = '\n',\n  FIRSTROW = 1\n);<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>file_path \u662f\u8981\u5bfc\u5165\u7684\u6570\u636e\u6587\u4ef6\u8def\u5f84<\/li>\n<li>FIELDTERMINATOR \u662f\u5206\u9694\u6bcf\u5217\u6570\u636e\u7684\u5b57\u7b26\uff08\u4f8b\u5982\u9017\u53f7\u6216\u5236\u8868\u7b26\uff09<\/li>\n<li>ROWTERMINATOR \u662f\u5206\u9694\u6bcf\u884c\u7684\u5b57\u7b26\uff08\u901a\u5e38\u662f\u6362\u884c\u7b26\uff09<\/li>\n<li>FIRSTROW \u6307\u5b9a\u8981\u8df3\u8fc7\u7684\u884c\u6570\uff08\u4f8b\u5982\u6807\u9898\u884c\uff09<\/li>\n<\/ul>\n<p>\u4f8b\u5982\uff0c\u4ee5\u4e0b\u8bed\u53e5\u4ece\u540d\u4e3a data.csv \u7684\u6587\u4ef6\u5c06\u6570\u636e\u5bfc\u5165\u5230 customers \u8868\u4e2d\uff0c\u5176\u4e2d\u9017\u53f7\u7528\u4f5c\u5b57\u6bb5\u5206\u9694\u7b26\uff0c\u6362\u884c\u7b26\u7528\u4f5c\u884c\u5206\u9694\u7b26\uff0c\u7b2c\u4e00\u884c\u5305\u542b\u6807\u9898\uff1a<\/p>\n<pre>BULK INSERT customers FROM 'data.csv' WITH (\n  FIELDTERMINATOR = ',',\n  ROWTERMINATOR = '\n',\n  FIRSTROW = 1\n);<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fsql\u600e\u6837\u5bfc\u5165\u6570\u636e\u5e93\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 sql \u4e2d\uff0c\u6570\u636e\u5bfc\u5165\u53ef\u4ee5\u901a\u8fc7\u4e24\u79cd\u65b9\u6cd5\u5b9e\u73b0\uff1ainsert \u8bed\u53e5\uff1a\u9010\u884c\u63d2\u5165\u6570\u636e\uff0c\u8bed\u6cd5\u4e3a insert into table_name (column1, &#8230;) values (value1, &#8230;)\u3002bulk insert\uff1a\u4ece\u6587\u4ef6\u6216\u6570\u636e\u5e93\u5feb\u901f\u6279\u91cf\u5bfc\u5165\u6570\u636e\uff0c\u8bed\u6cd5\u4e3a bulk insert table_name from &#8216;file_path&#8217; with (fieldterminator = &#8216;,&#8217;, rowterminator = &#8216; &#8216;, firstrow = 1)\u3002 \u5982\u4f55\u5c06\u6570\u636e\u5bfc\u5165\u6570\u636e\u5e93 \u5bfc\u5165\u6570\u636e\u662f\u5c06\u5916\u90e8\u6570\u636e\u52a0\u8f7d\u5230\u6570\u636e\u5e93\u4e2d\u7684\u8fc7\u7a0b\uff0c\u53ef\u4ee5\u4e3a\u5206\u6790\u3001\u5904\u7406\u6216\u5b58\u50a8\u76ee\u7684\u63d0\u4f9b\u6570\u636e\u3002\u5728 SQL \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u65b9\u6cd5\u6765\u5bfc\u5165\u6570\u636e\uff0c\u4e0b\u9762\u6211\u4eec\u5c06\u4ecb\u7ecd\u6700\u5e38\u7528\u7684\u4e24\u79cd\u65b9\u6cd5\uff1a INSERT \u8bed\u53e5 INSERT \u8bed\u53e5\u5141\u8bb8\u60a8\u5c06\u5355\u4e2a\u6216\u591a\u4e2a\u8bb0\u5f55\u63d2\u5165\u8868\u4e2d\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a INSERT INTO table_name (column1, column2, &#8230;) VALUES (value1, value2, &#8230;); \u767b\u5f55\u540e\u590d\u5236 \u4f8b\u5982\uff0c\u4ee5\u4e0b\u8bed\u53e5\u5c06\u4e24\u6761\u8bb0\u5f55\u63d2\u5165\u540d\u4e3a customers \u7684\u8868\u4e2d\uff1a INSERT INTO customers (name, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-6256","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6256","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=6256"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6256\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6256"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6256"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6256"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}