{"id":5633,"date":"2024-11-14T12:26:42","date_gmt":"2024-11-14T04:26:42","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5633\/"},"modified":"2024-11-14T12:26:42","modified_gmt":"2024-11-14T04:26:42","slug":"sql%e6%95%b0%e6%8d%ae%e5%ba%93%e7%8a%b6%e6%80%81%e6%80%8e%e4%b9%88%e8%a1%a8%e7%a4%ba","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5633\/","title":{"rendered":"sql\u6570\u636e\u5e93\u72b6\u6001\u600e\u4e48\u8868\u793a"},"content":{"rendered":"<blockquote><p>\n  sql \u6570\u636e\u5e93\u72b6\u6001\u901a\u5e38\u4f7f\u7528 sqlstate \u4ee3\u7801\u3001\u6267\u884c\u72b6\u6001\u3001\u670d\u52a1\u5668\u9519\u8bef\u53f7\u548c\u9519\u8bef\u6d88\u606f\u6765\u8868\u793a\u3002sqlstate \u4ee3\u7801\u662f\u4e00\u4e2a\u6807\u51c6\u5316\u7684\u4e94\u4f4d\u6570\u5b57\u4ee3\u7801\uff0c\u7528\u4e8e\u6307\u793a\u9519\u8bef\u7c7b\u578b\u3002\u6267\u884c\u72b6\u6001\u8868\u793a\u67e5\u8be2\u6216\u8bed\u53e5\u662f\u5426\u6210\u529f\u6267\u884c\u3002\u670d\u52a1\u5668\u9519\u8bef\u53f7\u662f\u6570\u636e\u5e93\u670d\u52a1\u5668\u4ea7\u751f\u7684\u7279\u5b9a\u4e8e\u5b9e\u73b0\u7684\u9519\u8bef\u4ee3\u7801\u3002\u9519\u8bef\u6d88\u606f\u63d0\u4f9b\u6709\u5173 sql \u9519\u8bef\u6216\u8b66\u544a\u7684\u8be6\u7ec6\u6587\u672c\u63cf\u8ff0\u3002\u4e86\u89e3\u8fd9\u4e9b\u72b6\u6001\u8868\u793a\u5bf9\u4e8e\u8bca\u65ad\u548c\u89e3\u51b3 sql \u9519\u8bef\u81f3\u5173\u91cd\u8981\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/30\/2024053019244751929.jpg\" class=\"aligncenter\" title=\"sql\u6570\u636e\u5e93\u72b6\u6001\u600e\u4e48\u8868\u793a\u63d2\u56fe\" alt=\"sql\u6570\u636e\u5e93\u72b6\u6001\u600e\u4e48\u8868\u793a\u63d2\u56fe\" \/><\/p>\n<p><strong>SQL \u6570\u636e\u5e93\u72b6\u6001<\/strong><\/p>\n<p><strong>Q\uff1aSQL \u6570\u636e\u5e93\u72b6\u6001\u5982\u4f55\u8868\u793a\uff1f<\/strong><\/p>\n<p><strong>A\uff1a<\/strong>SQL \u6570\u636e\u5e93\u72b6\u6001\u901a\u5e38\u4f7f\u7528\u4ee5\u4e0b\u51e0\u79cd\u65b9\u5f0f\u8868\u793a\uff1a<\/p>\n<p><strong>1. SQLSTATE \u4ee3\u7801<\/strong><\/p>\n<p>SQLSTATE \u4ee3\u7801\u662f\u4e00\u4e2a\u6807\u51c6\u5316\u7684\u4e94\u4f4d\u6570\u5b57\u4ee3\u7801\uff0c\u7528\u4e8e\u6307\u793a SQL \u9519\u8bef\u6216\u8b66\u544a\u7684\u7c7b\u578b\u3002\u4f8b\u5982\uff1a<\/p>\n<ul>\n<li>00000 &#8211; \u6ca1\u6709\u9519\u8bef\u6216\u8b66\u544a<\/li>\n<li>23000 &#8211; \u5b8c\u6574\u6027\u7ea6\u675f\u8fdd\u4f8b<\/li>\n<li>40001 &#8211; \u8bed\u6cd5\u9519\u8bef<\/li>\n<\/ul>\n<p><strong>2. \u6267\u884c\u72b6\u6001<\/strong><\/p>\n<p>\u6267\u884c\u72b6\u6001\u8868\u793a\u6570\u636e\u5e93\u662f\u5426\u6210\u529f\u6267\u884c\u4e86\u67e5\u8be2\u6216\u8bed\u53e5\u3002\u5e38\u89c1\u7684\u6267\u884c\u72b6\u6001\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>0 &#8211; \u6210\u529f<\/li>\n<li>1 &#8211; \u9519\u8bef<\/li>\n<li>2 &#8211; \u8b66\u544a<\/li>\n<\/ul>\n<p><strong>3. \u670d\u52a1\u5668\u9519\u8bef\u53f7<\/strong><\/p>\n<p>\u670d\u52a1\u5668\u9519\u8bef\u53f7\u662f\u6570\u636e\u5e93\u670d\u52a1\u5668\u4ea7\u751f\u7684\u7279\u5b9a\u4e8e\u5b9e\u73b0\u7684\u9519\u8bef\u4ee3\u7801\u3002\u6bcf\u4e2a\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf (DBMS) \u90fd\u53ef\u80fd\u4f7f\u7528\u4e0d\u540c\u7684\u9519\u8bef\u53f7\u7cfb\u7edf\u3002<\/p>\n<p><strong>4. \u9519\u8bef\u6d88\u606f<\/strong><\/p>\n<p>\u9519\u8bef\u6d88\u606f\u662f\u4e00\u6bb5\u6587\u672c\u63cf\u8ff0\uff0c\u63d0\u4f9b\u4e86\u6709\u5173 SQL \u9519\u8bef\u6216\u8b66\u544a\u7684\u66f4\u591a\u8be6\u7ec6\u4fe1\u606f\u3002<\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>SELECT * FROM customers;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5982\u679c\u6b64\u67e5\u8be2\u5bfc\u81f4\u5b8c\u6574\u6027\u7ea6\u675f\u8fdd\u4f8b\uff0c\u5b83\u53ef\u80fd\u4f1a\u8fd4\u56de\u4ee5\u4e0b\u72b6\u6001\u4fe1\u606f\uff1a<\/p>\n<ul>\n<li> <strong>SQLSTATE \u4ee3\u7801\uff1a<\/strong> 23000<\/li>\n<li> <strong>\u6267\u884c\u72b6\u6001\uff1a<\/strong> 1<\/li>\n<li> <strong>\u9519\u8bef\u53f7\uff1a<\/strong> 1062<\/li>\n<li> <strong>\u9519\u8bef\u6d88\u606f\uff1a<\/strong> &#8220;Duplicate entry &#8216;john&#8217; for key &#8216;PRIMARY'&#8221;<\/li>\n<\/ul>\n<p><strong>\u91cd\u8981\u63d0\u793a\uff1a<\/strong><\/p>\n<ul>\n<li>SQL \u72b6\u6001\u662f\u8de8\u5e73\u53f0\u901a\u7528\u7684\uff0c\u800c\u9519\u8bef\u53f7\u548c\u9519\u8bef\u6d88\u606f\u5219\u7279\u5b9a\u4e8e DBMS\u3002<\/li>\n<li>\u4e86\u89e3\u8fd9\u4e9b\u72b6\u6001\u8868\u793a\u5bf9\u4e8e\u8bca\u65ad\u548c\u89e3\u51b3 SQL \u9519\u8bef\u662f\u81f3\u5173\u91cd\u8981\u7684\u3002<\/li>\n<li>\u4e0d\u540c\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf\u53ef\u80fd\u6709\u4e0d\u540c\u7684\u65b9\u5f0f\u6765\u663e\u793a\u6216\u5904\u7406\u72b6\u6001\u4fe1\u606f\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fsql\u6570\u636e\u5e93\u72b6\u6001\u600e\u4e48\u8868\u793a\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>sql \u6570\u636e\u5e93\u72b6\u6001\u901a\u5e38\u4f7f\u7528 sqlstate \u4ee3\u7801\u3001\u6267\u884c\u72b6\u6001\u3001\u670d\u52a1\u5668\u9519\u8bef\u53f7\u548c\u9519\u8bef\u6d88\u606f\u6765\u8868\u793a\u3002sqlstate \u4ee3\u7801\u662f\u4e00\u4e2a\u6807\u51c6\u5316\u7684\u4e94\u4f4d\u6570\u5b57\u4ee3\u7801\uff0c\u7528\u4e8e\u6307\u793a\u9519\u8bef\u7c7b\u578b\u3002\u6267\u884c\u72b6\u6001\u8868\u793a\u67e5\u8be2\u6216\u8bed\u53e5\u662f\u5426\u6210\u529f\u6267\u884c\u3002\u670d\u52a1\u5668\u9519\u8bef\u53f7\u662f\u6570\u636e\u5e93\u670d\u52a1\u5668\u4ea7\u751f\u7684\u7279\u5b9a\u4e8e\u5b9e\u73b0\u7684\u9519\u8bef\u4ee3\u7801\u3002\u9519\u8bef\u6d88\u606f\u63d0\u4f9b\u6709\u5173 sql \u9519\u8bef\u6216\u8b66\u544a\u7684\u8be6\u7ec6\u6587\u672c\u63cf\u8ff0\u3002\u4e86\u89e3\u8fd9\u4e9b\u72b6\u6001\u8868\u793a\u5bf9\u4e8e\u8bca\u65ad\u548c\u89e3\u51b3 sql \u9519\u8bef\u81f3\u5173\u91cd\u8981\u3002 SQL \u6570\u636e\u5e93\u72b6\u6001 Q\uff1aSQL \u6570\u636e\u5e93\u72b6\u6001\u5982\u4f55\u8868\u793a\uff1f A\uff1aSQL \u6570\u636e\u5e93\u72b6\u6001\u901a\u5e38\u4f7f\u7528\u4ee5\u4e0b\u51e0\u79cd\u65b9\u5f0f\u8868\u793a\uff1a 1. SQLSTATE \u4ee3\u7801 SQLSTATE \u4ee3\u7801\u662f\u4e00\u4e2a\u6807\u51c6\u5316\u7684\u4e94\u4f4d\u6570\u5b57\u4ee3\u7801\uff0c\u7528\u4e8e\u6307\u793a SQL \u9519\u8bef\u6216\u8b66\u544a\u7684\u7c7b\u578b\u3002\u4f8b\u5982\uff1a 00000 &#8211; \u6ca1\u6709\u9519\u8bef\u6216\u8b66\u544a 23000 &#8211; \u5b8c\u6574\u6027\u7ea6\u675f\u8fdd\u4f8b 40001 &#8211; \u8bed\u6cd5\u9519\u8bef 2. \u6267\u884c\u72b6\u6001 \u6267\u884c\u72b6\u6001\u8868\u793a\u6570\u636e\u5e93\u662f\u5426\u6210\u529f\u6267\u884c\u4e86\u67e5\u8be2\u6216\u8bed\u53e5\u3002\u5e38\u89c1\u7684\u6267\u884c\u72b6\u6001\u5305\u62ec\uff1a 0 &#8211; \u6210\u529f 1 &#8211; \u9519\u8bef 2 &#8211; \u8b66\u544a 3. \u670d\u52a1\u5668\u9519\u8bef\u53f7 \u670d\u52a1\u5668\u9519\u8bef\u53f7\u662f\u6570\u636e\u5e93\u670d\u52a1\u5668\u4ea7\u751f\u7684\u7279\u5b9a\u4e8e\u5b9e\u73b0\u7684\u9519\u8bef\u4ee3\u7801\u3002\u6bcf\u4e2a\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf (DBMS) \u90fd\u53ef\u80fd\u4f7f\u7528\u4e0d\u540c\u7684\u9519\u8bef\u53f7\u7cfb\u7edf\u3002 4. \u9519\u8bef\u6d88\u606f \u9519\u8bef\u6d88\u606f\u662f\u4e00\u6bb5\u6587\u672c\u63cf\u8ff0\uff0c\u63d0\u4f9b\u4e86\u6709\u5173 SQL \u9519\u8bef\u6216\u8b66\u544a\u7684\u66f4\u591a\u8be6\u7ec6\u4fe1\u606f\u3002 \u793a\u4f8b\uff1a SELECT [&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-5633","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5633","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=5633"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5633\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5633"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5633"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5633"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}