{"id":76,"date":"2025-02-16T21:35:59","date_gmt":"2025-02-16T13:35:59","guid":{"rendered":"https:\/\/luwuge.cn\/?p=76"},"modified":"2025-02-16T21:35:59","modified_gmt":"2025-02-16T13:35:59","slug":"%e5%b0%8f%e7%99%bd%e6%95%b0%e6%8d%ae%e5%ba%93%e6%95%99%e5%ad%a6","status":"publish","type":"post","link":"https:\/\/luwuge.cn\/index.php\/2025\/02\/16\/%e5%b0%8f%e7%99%bd%e6%95%b0%e6%8d%ae%e5%ba%93%e6%95%99%e5%ad%a6\/","title":{"rendered":"\u5c0f\u767d\u6570\u636e\u5e93\u6559\u5b66"},"content":{"rendered":"\n<p>\u8ba9\u4e00\u4e2a\u5b8c\u5168\u6ca1\u6709\u6570\u636e\u5e93\u57fa\u7840\u7684\u4eba\u5feb\u901f\u8ba4\u8bc6 SQL \u6570\u636e\u5e93\u7ed3\u6784\uff0c\u53ef\u4ee5\u91c7\u53d6\u4ee5\u4e0b\u65b9\u6cd5\uff1a<\/p>\n\n\n\n<p><strong>1. \u7c7b\u6bd4\u751f\u6d3b\u573a\u666f<\/strong><\/p>\n\n\n\n<p>\u2022&nbsp;<strong>\u6570\u636e\u5e93\uff08Database\uff09<\/strong>\uff1a\u76f8\u5f53\u4e8e\u4e00\u4e2a&nbsp;<strong>\u6587\u4ef6\u67dc<\/strong>\uff0c\u91cc\u9762\u5b58\u653e\u7740\u5f88\u591a&nbsp;<strong>\u6587\u4ef6\u5939<\/strong>\uff08\u8868\uff09\u3002<\/p>\n\n\n\n<p>\u2022&nbsp;<strong>\u8868\uff08Table\uff09<\/strong>\uff1a\u5c31\u50cf Excel \u91cc\u7684\u4e00\u4e2a\u5de5\u4f5c\u8868\uff0c\u6bcf\u4e00\u884c\u662f\u4e00\u6761\u6570\u636e\uff0c\u6bcf\u4e00\u5217\u662f\u67d0\u4e2a\u5c5e\u6027\u3002<\/p>\n\n\n\n<p>\u2022&nbsp;<strong>\u5b57\u6bb5\uff08Column\uff09<\/strong>\uff1a\u76f8\u5f53\u4e8e Excel \u91cc\u7684&nbsp;<strong>\u5217<\/strong>\uff0c\u6bcf\u4e00\u5217\u4ee3\u8868\u6570\u636e\u7684\u67d0\u4e2a\u7279\u6027\uff08\u5982\u201c\u59d3\u540d\u201d\u3001\u201c\u5e74\u9f84\u201d\uff09\u3002<\/p>\n\n\n\n<p>\u2022&nbsp;<strong>\u884c\uff08Row\uff09<\/strong>\uff1a\u76f8\u5f53\u4e8e Excel \u91cc\u7684&nbsp;<strong>\u884c<\/strong>\uff0c\u6bcf\u4e00\u884c\u662f\u4e00\u6761\u5b8c\u6574\u7684\u8bb0\u5f55\uff08\u6bd4\u5982\u67d0\u4e2a\u5b66\u751f\u7684\u6240\u6709\u4fe1\u606f\uff09\u3002<\/p>\n\n\n\n<p>\u2022&nbsp;<strong>\u4e3b\u952e\uff08Primary Key\uff09<\/strong>\uff1a\u7c7b\u4f3c\u4e8e\u8eab\u4efd\u8bc1\u53f7\uff0c\u4fdd\u8bc1\u6bcf\u4e2a\u4eba\u552f\u4e00\u53ef\u8bc6\u522b\u3002<\/p>\n\n\n\n<p>\u2022&nbsp;<strong>\u5916\u952e\uff08Foreign Key\uff09<\/strong>\uff1a\u7c7b\u4f3c\u4e8e\u5b66\u751f\u7684\u73ed\u7ea7\u7f16\u53f7\uff0c\u7528\u6765\u8fde\u63a5\u4e0d\u540c\u7684\u8868\u3002<\/p>\n\n\n\n<p><strong>2. \u7528\u7b80\u5355\u7684\u8868\u7ed3\u6784\u4e3e\u4f8b<\/strong><\/p>\n\n\n\n<p>\u5047\u8bbe\u662f\u4e00\u4e2a\u7ba1\u7406\u5b66\u751f\u4fe1\u606f\u7684\u6570\u636e\u5e93\uff0c\u6709\u4e24\u4e2a\u8868\uff1a<\/p>\n\n\n\n<p><strong>\u2460 \u5b66\u751f\u8868\uff08students\uff09<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th><strong>id\uff08\u4e3b\u952e\uff09<\/strong><\/th><th><strong>name<\/strong><\/th><th><strong>age<\/strong><\/th><th><strong>class_id\uff08\u5916\u952e\uff09<\/strong><\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td>\u5c0f\u660e<\/td><td>10<\/td><td>101<\/td><\/tr><tr><td>2<\/td><td>\u5c0f\u7ea2<\/td><td>11<\/td><td>102<\/td><\/tr><tr><td>3<\/td><td>\u5c0f\u521a<\/td><td>10<\/td><td>101<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>\u2461 \u73ed\u7ea7\u8868\uff08classes\uff09<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th><strong>class_id\uff08\u4e3b\u952e\uff09<\/strong><\/th><th><strong>class_name<\/strong><\/th><\/tr><\/thead><tbody><tr><td>101<\/td><td>\u4e09\u5e74\u7ea7\u4e00\u73ed<\/td><\/tr><tr><td>102<\/td><td>\u4e09\u5e74\u7ea7\u4e8c\u73ed<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\ud83d\udd39&nbsp;<strong>\u8fde\u63a5\u4e24\u4e2a\u8868\u7684\u65b9\u6cd5<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT students.name, classes.class_name\nFROM students\nJOIN classes ON students.class_id = classes.class_id;<\/code><\/pre>\n\n\n\n<p>\ud83d\udccc \u7ed3\u679c\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th><strong>name<\/strong><\/th><th><strong>class_name<\/strong><\/th><\/tr><\/thead><tbody><tr><td>\u5c0f\u660e<\/td><td>\u4e09\u5e74\u7ea7\u4e00\u73ed<\/td><\/tr><tr><td>\u5c0f\u7ea2<\/td><td>\u4e09\u5e74\u7ea7\u4e8c\u73ed<\/td><\/tr><tr><td>\u5c0f\u521a<\/td><td>\u4e09\u5e74\u7ea7\u4e00\u73ed<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>3. \u624b\u628a\u624b\u64cd\u4f5c\uff1a\u7528 SQLite \u8fdb\u884c\u4f53\u9a8c<\/strong><\/p>\n\n\n\n<p>\u5982\u679c\u5bf9\u65b9\u8fde SQL \u90fd\u6ca1\u63a5\u89e6\u8fc7\uff0c\u63a8\u8350&nbsp;<strong>SQLite<\/strong>\uff0c\u56e0\u4e3a\u5b83\u7b80\u5355\u6613\u4e0a\u624b\uff1a<\/p>\n\n\n\n<p>1.&nbsp;\u4e0b\u8f7d SQLite\uff08\u6216\u8005\u4f7f\u7528\u5728\u7ebf SQL \u7ec3\u4e60\u5e73\u53f0 https:\/\/sqliteonline.com\/\uff09<\/p>\n\n\n\n<p>2.&nbsp;\u6267\u884c\u4ee5\u4e0b SQL \u4ee3\u7801\uff0c\u521b\u5efa\u8868\u5e76\u63d2\u5165\u6570\u636e\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE students (\n    id INTEGER PRIMARY KEY,\n    name TEXT,\n    age INTEGER,\n    class_id INTEGER\n);\n\nCREATE TABLE classes (\n    class_id INTEGER PRIMARY KEY,\n    class_name TEXT\n);\n\nINSERT INTO students VALUES (1, '\u5c0f\u660e', 10, 101);\nINSERT INTO students VALUES (2, '\u5c0f\u7ea2', 11, 102);\nINSERT INTO students VALUES (3, '\u5c0f\u521a', 10, 101);\n\nINSERT INTO classes VALUES (101, '\u4e09\u5e74\u7ea7\u4e00\u73ed');\nINSERT INTO classes VALUES (102, '\u4e09\u5e74\u7ea7\u4e8c\u73ed');<\/code><\/pre>\n\n\n\n<p>3.&nbsp;\u8ba9\u5bf9\u65b9\u6267\u884c\u67e5\u8be2\uff0c\u770b\u5230\u6570\u636e\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT * FROM students;\nSELECT * FROM classes;<\/code><\/pre>\n\n\n\n<p><strong>4. \u5f15\u5bfc\u7406\u89e3 SQL \u8bed\u53e5<\/strong><\/p>\n\n\n\n<p>\u2022&nbsp;<strong>\u589e\uff08INSERT\uff09<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>INSERT INTO students (id, name, age, class_id) VALUES (4, '\u5c0f\u7f8e', 9, 102);<\/code><\/pre>\n\n\n\n<p>\u2022&nbsp;<strong>\u67e5\uff08SELECT\uff09<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT * FROM students WHERE age = 10;<\/code><\/pre>\n\n\n\n<p>\u2022&nbsp;<strong>\u6539\uff08UPDATE\uff09<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>UPDATE students SET age = 12 WHERE name = '\u5c0f\u7ea2';<\/code><\/pre>\n\n\n\n<p>\u2022&nbsp;<strong>\u5220\uff08DELETE\uff09<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>DELETE FROM students WHERE id = 3;<\/code><\/pre>\n\n\n\n<p><strong>5. \u603b\u7ed3<\/strong><\/p>\n\n\n\n<p>\u2022&nbsp;<strong>\u6570\u636e\u5e93<\/strong>&nbsp;\u5c31\u662f\u5b58\u6570\u636e\u7684\u5730\u65b9\uff0c\u5c31\u50cf Excel \u8868\u683c\u3002<\/p>\n\n\n\n<p>\u2022&nbsp;<strong>\u8868<\/strong>&nbsp;\u5c31\u662f Excel \u7684\u4e00\u4e2a Sheet\uff0c\u91cc\u9762\u6709\u884c\u548c\u5217\u3002<\/p>\n\n\n\n<p>\u2022&nbsp;<strong>SQL \u8bed\u8a00<\/strong>&nbsp;\u7528\u6765\u64cd\u4f5c\u6570\u636e\u5e93\uff0c\u6bd4\u5982\uff1a<\/p>\n\n\n\n<p>\u2022&nbsp;SELECT&nbsp;\u67e5\u8be2<\/p>\n\n\n\n<p>\u2022&nbsp;INSERT&nbsp;\u63d2\u5165<\/p>\n\n\n\n<p>\u2022&nbsp;UPDATE&nbsp;\u4fee\u6539<\/p>\n\n\n\n<p>\u2022&nbsp;DELETE&nbsp;\u5220\u9664<\/p>\n\n\n\n<p>\u5982\u679c\u5bf9\u65b9\u80fd&nbsp;<strong>\u8ddf\u7740\u505a\u4e00\u904d SQLite \u7ec3\u4e60<\/strong>\uff0c\u57fa\u672c\u5c31\u80fd\u5efa\u7acb SQL \u6570\u636e\u5e93\u7684\u57fa\u7840\u6982\u5ff5\u4e86\uff01\ud83d\ude80<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8ba9\u4e00\u4e2a\u5b8c\u5168\u6ca1\u6709\u6570\u636e\u5e93\u57fa\u7840\u7684\u4eba\u5feb\u901f\u8ba4\u8bc6 SQL \u6570\u636e\u5e93\u7ed3\u6784\uff0c\u53ef\u4ee5\u91c7\u53d6\u4ee5\u4e0b\u65b9\u6cd5\uff1a 1. \u7c7b\u6bd4\u751f\u6d3b\u573a\u666f \u2022&#038;nbsp [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[14],"class_list":["post-76","post","type-post","status-publish","format-standard","hentry","category-12","tag-14"],"_links":{"self":[{"href":"https:\/\/luwuge.cn\/index.php\/wp-json\/wp\/v2\/posts\/76","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/luwuge.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/luwuge.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/luwuge.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/luwuge.cn\/index.php\/wp-json\/wp\/v2\/comments?post=76"}],"version-history":[{"count":0,"href":"https:\/\/luwuge.cn\/index.php\/wp-json\/wp\/v2\/posts\/76\/revisions"}],"wp:attachment":[{"href":"https:\/\/luwuge.cn\/index.php\/wp-json\/wp\/v2\/media?parent=76"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/luwuge.cn\/index.php\/wp-json\/wp\/v2\/categories?post=76"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/luwuge.cn\/index.php\/wp-json\/wp\/v2\/tags?post=76"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}