{"id":179454,"date":"2024-11-09T01:57:18","date_gmt":"2024-11-08T17:57:18","guid":{"rendered":"https:\/\/server.hk\/cnblog\/179454\/"},"modified":"2024-11-09T01:57:19","modified_gmt":"2024-11-08T17:57:19","slug":"%e5%a6%82%e4%bd%95%e5%84%aa%e9%9b%85%e5%9c%b0%e5%bb%ba%e7%ab%8b%e6%95%b8%e6%93%9a%e5%ba%ab%e5%92%8c%e7%b7%a8%e5%af%ab-sql-%e8%aa%9e%e5%8f%a5%ef%bc%9f-%e6%95%b8%e6%93%9a%e5%ba%ab%e5%bb%ba%e7%ab%8b","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/179454\/","title":{"rendered":"\u5982\u4f55\u512a\u96c5\u5730\u5efa\u7acb\u6578\u64da\u5eab\u548c\u7de8\u5beb SQL \u8a9e\u53e5\uff1f (\u6578\u64da\u5eab\u5efa\u7acb\u904e\u7a0b sql \u8a9e\u53e5)"},"content":{"rendered":"<h1 id=\"%e5%a6%82%e4%bd%95%e5%84%aa%e9%9b%85%e5%9c%b0%e5%bb%ba%e7%ab%8b%e6%95%b8%e6%93%9a%e5%ba%ab%e5%92%8c%e7%b7%a8%e5%af%ab-sql-%e8%aa%9e%e5%8f%a5%ef%bc%9f-EonRPISEAi\">\u5982\u4f55\u512a\u96c5\u5730\u5efa\u7acb\u6578\u64da\u5eab\u548c\u7de8\u5beb SQL \u8a9e\u53e5\uff1f<\/h1>\n<p>\u5728\u7576\u4eca\u6578\u64da\u9a45\u52d5\u7684\u4e16\u754c\u4e2d\uff0c\u6578\u64da\u5eab\u7684\u7ba1\u7406\u548c\u64cd\u4f5c\u8b8a\u5f97\u8d8a\u4f86\u8d8a\u91cd\u8981\u3002\u7121\u8ad6\u662f\u958b\u767c\u61c9\u7528\u7a0b\u5e8f\u9084\u662f\u9032\u884c\u6578\u64da\u5206\u6790\uff0c\u638c\u63e1\u6578\u64da\u5eab\u7684\u5efa\u7acb\u548c SQL \u8a9e\u53e5\u7684\u7de8\u5beb\u90fd\u662f\u5fc5\u4e0d\u53ef\u5c11\u7684\u6280\u80fd\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e\u5982\u4f55\u512a\u96c5\u5730\u5efa\u7acb\u6578\u64da\u5eab\u4ee5\u53ca\u7de8\u5beb SQL \u8a9e\u53e5\u7684\u904e\u7a0b\u3002<\/p>\n<h2 id=\"%e6%95%b8%e6%93%9a%e5%ba%ab%e7%9a%84%e5%bb%ba%e7%ab%8b%e9%81%8e%e7%a8%8b-EonRPISEAi\">\u6578\u64da\u5eab\u7684\u5efa\u7acb\u904e\u7a0b<\/h2>\n<p>\u5efa\u7acb\u6578\u64da\u5eab\u7684\u7b2c\u4e00\u6b65\u662f\u9078\u64c7\u5408\u9069\u7684\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff08DBMS\uff09\u3002\u5e38\u898b\u7684\u9078\u64c7\u5305\u62ec MySQL\u3001PostgreSQL\u3001SQLite \u548c Microsoft SQL Server \u7b49\u3002\u9078\u64c7\u597d DBMS \u5f8c\uff0c\u63a5\u4e0b\u4f86\u7684\u6b65\u9a5f\u5982\u4e0b\uff1a<\/p>\n<h3 id=\"1-%e8%a8%ad%e8%a8%88%e6%95%b8%e6%93%9a%e5%ba%ab%e7%b5%90%e6%a7%8b-EonRPISEAi\">1. \u8a2d\u8a08\u6578\u64da\u5eab\u7d50\u69cb<\/h3>\n<p>\u5728\u5efa\u7acb\u6578\u64da\u5eab\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u8a2d\u8a08\u6578\u64da\u5eab\u7684\u7d50\u69cb\u3002\u9019\u5305\u62ec\u78ba\u5b9a\u6578\u64da\u8868\u7684\u6578\u91cf\u3001\u6bcf\u500b\u6578\u64da\u8868\u7684\u5b57\u6bb5\u4ee5\u53ca\u5b57\u6bb5\u7684\u6578\u64da\u985e\u578b\u3002\u4f8b\u5982\uff0c\u5047\u8a2d\u6211\u5011\u8981\u5efa\u7acb\u4e00\u500b\u7528\u65bc\u7ba1\u7406\u66f8\u7c4d\u7684\u6578\u64da\u5eab\uff0c\u6211\u5011\u53ef\u80fd\u9700\u8981\u4e00\u500b\u540d\u70ba <code>books<\/code> \u7684\u6578\u64da\u8868\uff0c\u5305\u542b\u4ee5\u4e0b\u5b57\u6bb5\uff1a<\/p>\n<ul>\n<li><code>id<\/code> (\u6574\u6578\uff0c\u81ea\u589e\u4e3b\u9375)<\/li>\n<li><code>title<\/code> (\u5b57\u7b26\u4e32\uff0c\u66f8\u540d)<\/li>\n<li><code>author<\/code> (\u5b57\u7b26\u4e32\uff0c\u4f5c\u8005)<\/li>\n<li><code>published_date<\/code> (\u65e5\u671f\uff0c\u51fa\u7248\u65e5\u671f)<\/li>\n<li><code>price<\/code> (\u6d6e\u9ede\u6578\uff0c\u50f9\u683c)<\/li>\n<\/ul>\n<h3 id=\"2-%e4%bd%bf%e7%94%a8-sql-%e8%aa%9e%e5%8f%a5%e5%89%b5%e5%bb%ba%e6%95%b8%e6%93%9a%e5%ba%ab-EonRPISEAi\">2. \u4f7f\u7528 SQL \u8a9e\u53e5\u5275\u5efa\u6578\u64da\u5eab<\/h3>\n<p>\u8a2d\u8a08\u597d\u7d50\u69cb\u5f8c\uff0c\u53ef\u4ee5\u4f7f\u7528 SQL \u8a9e\u53e5\u4f86\u5275\u5efa\u6578\u64da\u5eab\u548c\u6578\u64da\u8868\u3002\u4ee5\u4e0b\u662f\u5275\u5efa\u6578\u64da\u5eab\u548c\u6578\u64da\u8868\u7684\u57fa\u672c SQL \u8a9e\u53e5\uff1a<\/p>\n<pre><code>CREATE DATABASE library;\n\nUSE library;\n\nCREATE TABLE books (\n    id INT AUTO_INCREMENT PRIMARY KEY,\n    title VARCHAR(255) NOT NULL,\n    author VARCHAR(255) NOT NULL,\n    published_date DATE,\n    price DECIMAL(10, 2)\n);<\/code><\/pre>\n<h2 id=\"%e7%b7%a8%e5%af%ab-sql-%e8%aa%9e%e5%8f%a5-EonRPISEAi\">\u7de8\u5beb SQL \u8a9e\u53e5<\/h2>\n<p>\u5728\u6578\u64da\u5eab\u548c\u6578\u64da\u8868\u5efa\u7acb\u5b8c\u6210\u5f8c\uff0c\u63a5\u4e0b\u4f86\u5c31\u662f\u7de8\u5beb SQL \u8a9e\u53e5\u4f86\u9032\u884c\u6578\u64da\u7684\u64cd\u4f5c\u3002SQL \u8a9e\u53e5\u4e3b\u8981\u5206\u70ba\u56db\u985e\uff1a\u67e5\u8a62\uff08SELECT\uff09\u3001\u63d2\u5165\uff08INSERT\uff09\u3001\u66f4\u65b0\uff08UPDATE\uff09\u548c\u522a\u9664\uff08DELETE\uff09\u3002<\/p>\n<h3 id=\"1-%e6%9f%a5%e8%a9%a2%e6%95%b8%e6%93%9a-EonRPISEAi\">1. \u67e5\u8a62\u6578\u64da<\/h3>\n<p>\u4f7f\u7528 <code>SELECT<\/code> \u8a9e\u53e5\u53ef\u4ee5\u5f9e\u6578\u64da\u8868\u4e2d\u67e5\u8a62\u6578\u64da\u3002\u4f8b\u5982\uff0c\u67e5\u8a62\u6240\u6709\u66f8\u7c4d\u7684\u66f8\u540d\u548c\u4f5c\u8005\uff1a<\/p>\n<pre><code>SELECT title, author FROM books;<\/code><\/pre>\n<h3 id=\"2-%e6%8f%92%e5%85%a5%e6%95%b8%e6%93%9a-EonRPISEAi\">2. \u63d2\u5165\u6578\u64da<\/h3>\n<p>\u4f7f\u7528 <code>INSERT INTO<\/code> \u8a9e\u53e5\u53ef\u4ee5\u5411\u6578\u64da\u8868\u4e2d\u63d2\u5165\u65b0\u6578\u64da\u3002\u4f8b\u5982\uff0c\u63d2\u5165\u4e00\u672c\u65b0\u66f8\uff1a<\/p>\n<pre><code>INSERT INTO books (title, author, published_date, price)\nVALUES ('\u5b78\u7fd2 SQL', '\u5f35\u4e09', '2023-01-01', 99.99);<\/code><\/pre>\n<h3 id=\"3-%e6%9b%b4%e6%96%b0%e6%95%b8%e6%93%9a-EonRPISEAi\">3. \u66f4\u65b0\u6578\u64da<\/h3>\n<p>\u4f7f\u7528 <code>UPDATE<\/code> \u8a9e\u53e5\u53ef\u4ee5\u66f4\u65b0\u6578\u64da\u8868\u4e2d\u7684\u6578\u64da\u3002\u4f8b\u5982\uff0c\u66f4\u65b0\u67d0\u672c\u66f8\u7684\u50f9\u683c\uff1a<\/p>\n<pre><code>UPDATE books\nSET price = 89.99\nWHERE title = '\u5b78\u7fd2 SQL';<\/code><\/pre>\n<h3 id=\"4-%e5%88%aa%e9%99%a4%e6%95%b8%e6%93%9a-EonRPISEAi\">4. \u522a\u9664\u6578\u64da<\/h3>\n<p>\u4f7f\u7528 <code>DELETE<\/code> \u8a9e\u53e5\u53ef\u4ee5\u522a\u9664\u6578\u64da\u8868\u4e2d\u7684\u6578\u64da\u3002\u4f8b\u5982\uff0c\u522a\u9664\u67d0\u672c\u66f8\uff1a<\/p>\n<pre><code>DELETE FROM books\nWHERE title = '\u5b78\u7fd2 SQL';<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-EonRPISEAi\">\u7e3d\u7d50<\/h2>\n<p>\u5efa\u7acb\u6578\u64da\u5eab\u548c\u7de8\u5beb SQL \u8a9e\u53e5\u662f\u4e00\u500b\u7cfb\u7d71\u5316\u7684\u904e\u7a0b\uff0c\u5f9e\u8a2d\u8a08\u6578\u64da\u5eab\u7d50\u69cb\u5230\u5be6\u969b\u64cd\u4f5c\u6578\u64da\uff0c\u90fd\u9700\u8981\u8b39\u614e\u8003\u616e\u3002\u638c\u63e1\u9019\u4e9b\u57fa\u672c\u6280\u80fd\u5f8c\uff0c\u60a8\u5c07\u80fd\u5920\u66f4\u6709\u6548\u5730\u7ba1\u7406\u548c\u64cd\u4f5c\u6578\u64da\u3002\u82e5\u60a8\u9700\u8981\u66f4\u9ad8\u6548\u7684\u6578\u64da\u5eab\u89e3\u6c7a\u65b9\u6848\uff0c\u8003\u616e\u4f7f\u7528 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u670d\u52d9\uff0c\u9019\u5c07\u70ba\u60a8\u7684\u6578\u64da\u5eab\u7ba1\u7406\u63d0\u4f9b\u66f4\u7a69\u5b9a\u7684\u74b0\u5883\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u512a\u96c5\u5730\u5efa\u7acb\u6578\u64da\u5eab\u4e26\u7de8\u5beb SQL \u8a9e\u53e5\uff0c\u638c\u63e1\u6578\u64da\u7ba1\u7406\u7684\u95dc\u9375\u6280\u5de7\uff0c\u63d0\u5347\u6578\u64da\u64cd\u4f5c\u6548\u7387\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-179454","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/179454","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=179454"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/179454\/revisions"}],"predecessor-version":[{"id":179455,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/179454\/revisions\/179455"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=179454"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=179454"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=179454"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}