{"id":170007,"date":"2024-11-06T20:22:18","date_gmt":"2024-11-06T12:22:18","guid":{"rendered":"https:\/\/server.hk\/cnblog\/170007\/"},"modified":"2024-11-06T20:22:19","modified_gmt":"2024-11-06T12:22:19","slug":"%e5%8d%97%e9%83%b5%e6%95%b8%e6%93%9a%e5%ba%ab%e5%af%a6%e9%a9%97%e4%b8%80%ef%bc%9a%e6%95%b8%e6%93%9a%e5%bb%ba%e6%a8%a1%e8%88%87sql%e6%9f%a5%e8%a9%a2-%e5%8d%97%e9%83%b5%e6%95%b8%e6%93%9a%e5%ba%ab","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/170007\/","title":{"rendered":"\u5357\u90f5\u6578\u64da\u5eab\u5be6\u9a57\u4e00\uff1a\u6578\u64da\u5efa\u6a21\u8207SQL\u67e5\u8a62 (\u5357\u90f5\u6578\u64da\u5eab\u5be6\u9a57\u4e00)"},"content":{"rendered":"<h1 id=\"%e5%8d%97%e9%83%b5%e6%95%b8%e6%93%9a%e5%ba%ab%e5%af%a6%e9%a9%97%e4%b8%80%ef%bc%9a%e6%95%b8%e6%93%9a%e5%bb%ba%e6%a8%a1%e8%88%87sql%e6%9f%a5%e8%a9%a2-JyYvVGiHkA\">\u5357\u90f5\u6578\u64da\u5eab\u5be6\u9a57\u4e00\uff1a\u6578\u64da\u5efa\u6a21\u8207SQL\u67e5\u8a62<\/h1>\n<p>\u5728\u7576\u4eca\u6578\u64da\u9a45\u52d5\u7684\u4e16\u754c\u4e2d\uff0c\u6578\u64da\u5eab\u7684\u8a2d\u8a08\u8207\u7ba1\u7406\u8b8a\u5f97\u8d8a\u4f86\u8d8a\u91cd\u8981\u3002\u5357\u90f5\u6578\u64da\u5eab\u5be6\u9a57\u4e00\u5c08\u6ce8\u65bc\u6578\u64da\u5efa\u6a21\u8207SQL\u67e5\u8a62\uff0c\u9019\u662f\u5b78\u7fd2\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff08DBMS\uff09\u7684\u4e00\u500b\u91cd\u8981\u6b65\u9a5f\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u6578\u64da\u5efa\u6a21\u7684\u57fa\u672c\u6982\u5ff5\u3001SQL\u67e5\u8a62\u7684\u57fa\u672c\u8a9e\u6cd5\uff0c\u4ee5\u53ca\u5982\u4f55\u5728\u5be6\u969b\u61c9\u7528\u4e2d\u904b\u7528\u9019\u4e9b\u77e5\u8b58\u3002<\/p>\n<h2 id=\"%e6%95%b8%e6%93%9a%e5%bb%ba%e6%a8%a1%e7%9a%84%e5%9f%ba%e6%9c%ac%e6%a6%82%e5%bf%b5-JyYvVGiHkA\">\u6578\u64da\u5efa\u6a21\u7684\u57fa\u672c\u6982\u5ff5<\/h2>\n<p>\u6578\u64da\u5efa\u6a21\u662f\u5c07\u696d\u52d9\u9700\u6c42\u8f49\u5316\u70ba\u6578\u64da\u7d50\u69cb\u7684\u904e\u7a0b\u3002\u5b83\u901a\u5e38\u5305\u62ec\u4ee5\u4e0b\u5e7e\u500b\u6b65\u9a5f\uff1a<\/p>\n<ul>\n<li><strong>\u9700\u6c42\u5206\u6790\uff1a<\/strong>\u4e86\u89e3\u696d\u52d9\u9700\u6c42\uff0c\u78ba\u5b9a\u9700\u8981\u5b58\u5132\u7684\u6578\u64da\u985e\u578b\u3002<\/li>\n<li><strong>\u6982\u5ff5\u6a21\u578b\uff1a<\/strong>\u4f7f\u7528\u5be6\u9ad4-\u95dc\u4fc2\u5716\uff08ER\u5716\uff09\u4f86\u8868\u793a\u6578\u64da\u4e4b\u9593\u7684\u95dc\u4fc2\u3002<\/li>\n<li><strong>\u908f\u8f2f\u6a21\u578b\uff1a<\/strong>\u6839\u64da\u6982\u5ff5\u6a21\u578b\u8a2d\u8a08\u908f\u8f2f\u7d50\u69cb\uff0c\u78ba\u5b9a\u6578\u64da\u8868\u53ca\u5176\u5c6c\u6027\u3002<\/li>\n<li><strong>\u7269\u7406\u6a21\u578b\uff1a<\/strong>\u6839\u64da\u908f\u8f2f\u6a21\u578b\u8a2d\u8a08\u5177\u9ad4\u7684\u6578\u64da\u5eab\u7d50\u69cb\uff0c\u5305\u62ec\u7d22\u5f15\u3001\u7d04\u675f\u7b49\u3002<\/li>\n<\/ul>\n<p>\u4f8b\u5982\uff0c\u5047\u8a2d\u6211\u5011\u8981\u8a2d\u8a08\u4e00\u500b\u7c21\u55ae\u7684\u5716\u66f8\u7ba1\u7406\u7cfb\u7d71\uff0c\u6211\u5011\u53ef\u80fd\u6703\u6709\u4ee5\u4e0b\u5e7e\u500b\u5be6\u9ad4\uff1a<\/p>\n<ul>\n<li>\u66f8\u7c4d\uff08Book\uff09<\/li>\n<li>\u4f5c\u8005\uff08Author\uff09<\/li>\n<li>\u8b80\u8005\uff08Reader\uff09<\/li>\n<\/ul>\n<p>\u9019\u4e9b\u5be6\u9ad4\u4e4b\u9593\u7684\u95dc\u4fc2\u53ef\u4ee5\u7528ER\u5716\u8868\u793a\uff0c\u66f8\u7c4d\u8207\u4f5c\u8005\u4e4b\u9593\u662f\u4e00\u5c0d\u591a\u7684\u95dc\u4fc2\uff0c\u800c\u8b80\u8005\u8207\u66f8\u7c4d\u4e4b\u9593\u5247\u662f\u591a\u5c0d\u591a\u7684\u95dc\u4fc2\u3002<\/p>\n<h2 id=\"sql%e6%9f%a5%e8%a9%a2%e7%9a%84%e5%9f%ba%e6%9c%ac%e8%aa%9e%e6%b3%95-JyYvVGiHkA\">SQL\u67e5\u8a62\u7684\u57fa\u672c\u8a9e\u6cd5<\/h2>\n<p>SQL\uff08\u7d50\u69cb\u5316\u67e5\u8a62\u8a9e\u8a00\uff09\u662f\u7528\u65bc\u8207\u6578\u64da\u5eab\u9032\u884c\u4ea4\u4e92\u7684\u6a19\u6e96\u8a9e\u8a00\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u57fa\u672c\u7684SQL\u67e5\u8a62\u8a9e\u6cd5\uff1a<\/p>\n<h3 id=\"1-%e5%89%b5%e5%bb%ba%e6%95%b8%e6%93%9a%e8%a1%a8-JyYvVGiHkA\">1. \u5275\u5efa\u6578\u64da\u8868<\/h3>\n<pre><code>\nCREATE TABLE Books (\n    BookID INT PRIMARY KEY,\n    Title VARCHAR(100),\n    AuthorID INT,\n    FOREIGN KEY (AuthorID) REFERENCES Authors(AuthorID)\n);\n<\/code><\/pre>\n<h3 id=\"2-%e6%8f%92%e5%85%a5%e6%95%b8%e6%93%9a-JyYvVGiHkA\">2. \u63d2\u5165\u6578\u64da<\/h3>\n<pre><code>\nINSERT INTO Books (BookID, Title, AuthorID) VALUES (1, '\u6578\u64da\u5eab\u7cfb\u7d71\u6982\u8ad6', 1);\n<\/code><\/pre>\n<h3 id=\"3-%e6%9f%a5%e8%a9%a2%e6%95%b8%e6%93%9a-JyYvVGiHkA\">3. \u67e5\u8a62\u6578\u64da<\/h3>\n<pre><code>\nSELECT * FROM Books WHERE AuthorID = 1;\n<\/code><\/pre>\n<h3 id=\"4-%e6%9b%b4%e6%96%b0%e6%95%b8%e6%93%9a-JyYvVGiHkA\">4. \u66f4\u65b0\u6578\u64da<\/h3>\n<pre><code>\nUPDATE Books SET Title = '\u6578\u64da\u5eab\u7cfb\u7d71' WHERE BookID = 1;\n<\/code><\/pre>\n<h3 id=\"5-%e5%88%aa%e9%99%a4%e6%95%b8%e6%93%9a-JyYvVGiHkA\">5. \u522a\u9664\u6578\u64da<\/h3>\n<pre><code>\nDELETE FROM Books WHERE BookID = 1;\n<\/code><\/pre>\n<p>\u9019\u4e9b\u57fa\u672c\u7684SQL\u64cd\u4f5c\u53ef\u4ee5\u5e6b\u52a9\u7528\u6236\u6709\u6548\u5730\u7ba1\u7406\u6578\u64da\u5eab\u4e2d\u7684\u6578\u64da\u3002\u901a\u904e\u9019\u4e9b\u67e5\u8a62\uff0c\u4f7f\u7528\u8005\u53ef\u4ee5\u8f15\u9b06\u5730\u9032\u884c\u6578\u64da\u7684\u589e\u522a\u6539\u67e5\uff0c\u5f9e\u800c\u6eff\u8db3\u696d\u52d9\u9700\u6c42\u3002<\/p>\n<h2 id=\"%e5%af%a6%e9%a9%97%e7%9a%84%e6%87%89%e7%94%a8%e8%88%87%e6%84%8f%e7%be%a9-JyYvVGiHkA\">\u5be6\u9a57\u7684\u61c9\u7528\u8207\u610f\u7fa9<\/h2>\n<p>\u5357\u90f5\u6578\u64da\u5eab\u5be6\u9a57\u4e00\u4e0d\u50c5\u50c5\u662f\u5b78\u7fd2\u6578\u64da\u5efa\u6a21\u8207SQL\u67e5\u8a62\u7684\u904e\u7a0b\uff0c\u66f4\u662f\u7406\u89e3\u6578\u64da\u5982\u4f55\u5728\u5be6\u969b\u61c9\u7528\u4e2d\u767c\u63ee\u4f5c\u7528\u7684\u95dc\u9375\u3002\u901a\u904e\u9019\u4e9b\u5be6\u9a57\uff0c\u5b78\u751f\u53ef\u4ee5\u638c\u63e1\u5982\u4f55\u8a2d\u8a08\u4e00\u500b\u6709\u6548\u7684\u6578\u64da\u5eab\uff0c\u4e26\u80fd\u5920\u4f7f\u7528SQL\u9032\u884c\u6578\u64da\u64cd\u4f5c\uff0c\u9019\u5c0d\u65bc\u672a\u4f86\u7684\u8077\u696d\u751f\u6daf\u662f\u975e\u5e38\u6709\u5e6b\u52a9\u7684\u3002<\/p>\n<p>\u6b64\u5916\uff0c\u96a8\u8457\u96f2\u8a08\u7b97\u548c\u5927\u6578\u64da\u6280\u8853\u7684\u767c\u5c55\uff0c\u6578\u64da\u5eab\u7684\u7ba1\u7406\u548c\u64cd\u4f5c\u8b8a\u5f97\u66f4\u52a0\u8907\u96dc\u3002\u638c\u63e1\u6578\u64da\u5efa\u6a21\u548cSQL\u67e5\u8a62\u7684\u57fa\u672c\u6280\u80fd\uff0c\u5c07\u4f7f\u5b78\u751f\u5728\u9019\u500b\u5feb\u901f\u8b8a\u5316\u7684\u9818\u57df\u4e2d\u4fdd\u6301\u7af6\u722d\u529b\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-JyYvVGiHkA\">\u7e3d\u7d50<\/h2>\n<p>\u5357\u90f5\u6578\u64da\u5eab\u5be6\u9a57\u4e00\u63d0\u4f9b\u4e86\u4e00\u500b\u826f\u597d\u7684\u5e73\u53f0\uff0c\u8b93\u5b78\u751f\u80fd\u5920\u6df1\u5165\u4e86\u89e3\u6578\u64da\u5efa\u6a21\u8207SQL\u67e5\u8a62\u7684\u57fa\u672c\u6982\u5ff5\u548c\u5be6\u8e10\u3002\u9019\u4e9b\u6280\u80fd\u4e0d\u50c5\u5c0d\u65bc\u5b78\u8853\u7814\u7a76\u6709\u5e6b\u52a9\uff0c\u4e5f\u5c0d\u65bc\u672a\u4f86\u7684\u8077\u696d\u767c\u5c55\u81f3\u95dc\u91cd\u8981\u3002\u82e5\u60a8\u5c0d\u65bc\u6578\u64da\u5eab\u7ba1\u7406\u6709\u9032\u4e00\u6b65\u7684\u9700\u6c42\uff0c\u8003\u616e\u4f7f\u7528<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u4f86\u642d\u5efa\u60a8\u7684\u6578\u64da\u5eab\u74b0\u5883\uff0c\u9019\u5c07\u70ba\u60a8\u7684\u5b78\u7fd2\u548c\u5be6\u8e10\u63d0\u4f9b\u66f4\u591a\u7684\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22\u5357\u90f5\u6578\u64da\u5eab\u5be6\u9a57\u4e00\uff0c\u5b78\u7fd2\u6578\u64da\u5efa\u6a21\u8207SQL\u67e5\u8a62\u6280\u5de7\uff0c\u63d0\u5347\u6578\u64da\u7ba1\u7406\u8207\u5206\u6790\u80fd\u529b\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-170007","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/170007","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=170007"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/170007\/revisions"}],"predecessor-version":[{"id":170008,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/170007\/revisions\/170008"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=170007"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=170007"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=170007"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}