{"id":1528,"date":"2025-02-10T23:51:02","date_gmt":"2025-02-10T15:51:02","guid":{"rendered":"https:\/\/www.laixuexila.com\/?p=1528"},"modified":"2025-02-10T23:51:03","modified_gmt":"2025-02-10T15:51:03","slug":"%e5%bc%80%e5%8f%91%e8%80%85%e5%b8%b8%e9%81%87%e7%9a%84sql%e9%97%ae%e9%a2%98%e5%8f%8a%e8%a7%a3%e5%86%b3%e6%96%b9%e6%a1%88%ef%bc%9a%e5%ae%9e%e7%94%a8%e6%8a%80%e5%b7%a7%e4%b8%8e%e5%ae%9e%e4%be%8b","status":"publish","type":"post","link":"https:\/\/www.laixuexila.com\/index.php\/2025\/02\/10\/%e5%bc%80%e5%8f%91%e8%80%85%e5%b8%b8%e9%81%87%e7%9a%84sql%e9%97%ae%e9%a2%98%e5%8f%8a%e8%a7%a3%e5%86%b3%e6%96%b9%e6%a1%88%ef%bc%9a%e5%ae%9e%e7%94%a8%e6%8a%80%e5%b7%a7%e4%b8%8e%e5%ae%9e%e4%be%8b\/","title":{"rendered":"\u5f00\u53d1\u8005\u5e38\u9047\u7684SQL\u95ee\u9898\u53ca\u89e3\u51b3\u65b9\u6848\uff1a\u5b9e\u7528\u6280\u5de7\u4e0e\u5b9e\u4f8b\u89e3\u6790"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u5728\u4f7f\u7528SQL\u65f6\uff0c\u5f00\u53d1\u8005\u5e38\u5e38\u4f1a\u9047\u5230\u5404\u79cd\u95ee\u9898\uff0c\u5f71\u54cd\u67e5\u8be2\u6548\u7387\u3001\u6570\u636e\u4e00\u81f4\u6027\u6216\u7cfb\u7edf\u6027\u80fd\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684SQL\u95ee\u9898\u53ca\u5176\u89e3\u51b3\u65b9\u6848\uff0c\u5e76\u9644\u5e26\u793a\u4f8b\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. <strong>\u95ee\u9898\uff1a\u67e5\u8be2\u6027\u80fd\u5dee<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u539f\u56e0\uff1a<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u67e5\u8be2\u6570\u636e\u91cf\u5927\u65f6\uff0cSQL\u6267\u884c\u7f13\u6162\uff0c\u901a\u5e38\u662f\u7531\u4e8e\u6ca1\u6709\u9002\u5f53\u7684\u7d22\u5f15\u6216\u67e5\u8be2\u8bbe\u8ba1\u4e0d\u5408\u7406\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4f7f\u7528\u7d22\u5f15\uff1a<\/strong> \u786e\u4fdd\u67e5\u8be2\u4e2d\u6d89\u53ca\u7684\u5217\u4e0a\u6709\u7d22\u5f15\uff0c\u7279\u522b\u662f <code>WHERE<\/code> \u5b50\u53e5\u4e2d\u4f7f\u7528\u7684\u5217\u3002<\/li>\n\n\n\n<li><strong>\u4f18\u5316\u67e5\u8be2\uff1a<\/strong> \u907f\u514d\u67e5\u8be2\u8fc7\u591a\u4e0d\u5fc5\u8981\u7684\u5217\uff0c\u4f7f\u7528 <code>JOIN<\/code> \u4ee3\u66ff\u5b50\u67e5\u8be2\uff0c\u907f\u514d\u4f7f\u7528 <code>SELECT *<\/code>\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u793a\u4f8b\uff1a<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>-- \u6dfb\u52a0\u7d22\u5f15\nCREATE INDEX idx_user_name ON users(name);\n\n-- \u4f18\u5316\u67e5\u8be2\uff0c\u907f\u514d\u4f7f\u7528 SELECT *\nSELECT name, email FROM users WHERE age &gt; 30;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2. <strong>\u95ee\u9898\uff1a\u6b7b\u9501<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u539f\u56e0\uff1a<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f53\u4e24\u4e2a\u6216\u591a\u4e2a\u4e8b\u52a1\u8bd5\u56fe\u8bbf\u95ee\u5bf9\u65b9\u6301\u6709\u7684\u9501\uff0c\u5e76\u4e14\u76f8\u4e92\u7b49\u5f85\u5bf9\u65b9\u91ca\u653e\u9501\u65f6\uff0c\u5c31\u4f1a\u53d1\u751f\u6b7b\u9501\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u907f\u514d\u957f\u65f6\u95f4\u6301\u9501\uff1a<\/strong> \u5c3d\u91cf\u51cf\u5c11\u4e8b\u52a1\u7684\u6267\u884c\u65f6\u95f4\uff0c\u907f\u514d\u5728\u4e8b\u52a1\u4e2d\u8fdb\u884c\u590d\u6742\u8ba1\u7b97\u3002<\/li>\n\n\n\n<li><strong>\u4e8b\u52a1\u987a\u5e8f\uff1a<\/strong> \u5c3d\u91cf\u4fdd\u6301\u7edf\u4e00\u7684\u4e8b\u52a1\u6267\u884c\u987a\u5e8f\uff0c\u4ee5\u907f\u514d\u5faa\u73af\u4f9d\u8d56\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u793a\u4f8b\uff1a<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>-- \u6b7b\u9501\u793a\u4f8b\uff0c\u4e24\u4e2a\u4e8b\u52a1\u5c1d\u8bd5\u83b7\u53d6\u5bf9\u65b9\u6301\u6709\u7684\u9501\nBEGIN;\nUPDATE accounts SET balance = balance - 100 WHERE id = 1; -- \u4e8b\u52a11\nUPDATE accounts SET balance = balance + 100 WHERE id = 2;\nCOMMIT;\n\nBEGIN;\nUPDATE accounts SET balance = balance - 50 WHERE id = 2; -- \u4e8b\u52a12\nUPDATE accounts SET balance = balance + 50 WHERE id = 1;\nCOMMIT;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u89e3\u51b3\u65b9\u6cd5\uff1a\u5c06\u4e8b\u52a1\u7684\u987a\u5e8f\u4fee\u6539\u4e3a\u4e00\u81f4\u7684\u6267\u884c\u987a\u5e8f\uff0c\u907f\u514d\u6b7b\u9501\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. <strong>\u95ee\u9898\uff1a\u6570\u636e\u4e0d\u4e00\u81f4<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u539f\u56e0\uff1a<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u591a\u6b21\u66f4\u65b0\u6570\u636e\u5e93\u65f6\u6ca1\u6709\u4e8b\u52a1\u7ba1\u7406\uff0c\u5bfc\u81f4\u64cd\u4f5c\u4e2d\u65ad\u65f6\u6570\u636e\u72b6\u6001\u4e0d\u4e00\u81f4\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4f7f\u7528\u4e8b\u52a1\uff1a<\/strong> \u786e\u4fdd\u5728\u591a\u4e2a\u64cd\u4f5c\u4e4b\u95f4\u4f7f\u7528\u4e8b\u52a1\uff0c\u4f7f\u7528 <code>COMMIT<\/code> \u6216 <code>ROLLBACK<\/code> \u6765\u786e\u4fdd\u539f\u5b50\u6027\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u793a\u4f8b\uff1a<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>-- \u4f7f\u7528\u4e8b\u52a1\u4fdd\u8bc1\u6570\u636e\u4e00\u81f4\u6027\nBEGIN;\n\nUPDATE accounts SET balance = balance - 100 WHERE user_id = 1;\nUPDATE accounts SET balance = balance + 100 WHERE user_id = 2;\n\n-- \u5982\u679c\u4e00\u5207\u6b63\u5e38\uff0c\u63d0\u4ea4\u4e8b\u52a1\nCOMMIT;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">4. <strong>\u95ee\u9898\uff1a\u67e5\u8be2\u7ed3\u679c\u5305\u542b\u91cd\u590d\u6570\u636e<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u539f\u56e0\uff1a<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u67e5\u8be2\u4e2d\u6ca1\u6709\u53bb\u9664\u91cd\u590d\u6570\u636e\uff0c\u5bfc\u81f4\u7ed3\u679c\u96c6\u4e2d\u7684\u6570\u636e\u91cd\u590d\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4f7f\u7528 <code>DISTINCT<\/code>\uff1a<\/strong> \u5982\u679c\u9700\u8981\u53bb\u9664\u91cd\u590d\u6570\u636e\uff0c\u53ef\u4ee5\u5728\u67e5\u8be2\u4e2d\u4f7f\u7528 <code>DISTINCT<\/code> \u5173\u952e\u5b57\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u793a\u4f8b\uff1a<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>-- \u4f7f\u7528 DISTINCT \u53bb\u91cd\nSELECT DISTINCT name FROM users WHERE age &gt; 30;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">5. <strong>\u95ee\u9898\uff1a\u672a\u5904\u7406NULL\u503c<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u539f\u56e0\uff1a<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u5904\u7406\u6570\u636e\u65f6\u6ca1\u6709\u8003\u8651 <code>NULL<\/code> \u503c\uff0c\u5bfc\u81f4\u67e5\u8be2\u7ed3\u679c\u4e0d\u7b26\u5408\u9884\u671f\u6216\u51fa\u73b0\u9519\u8bef\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4f7f\u7528 <code>IS NULL<\/code> \u6216 <code>IS NOT NULL<\/code>\uff1a<\/strong> \u5728\u67e5\u8be2\u65f6\u663e\u5f0f\u68c0\u67e5 <code>NULL<\/code> \u503c\u3002<\/li>\n\n\n\n<li><strong>\u4f7f\u7528 <code>COALESCE<\/code> \u6216 <code>IFNULL<\/code>\uff1a<\/strong> \u7528\u9ed8\u8ba4\u503c\u66ff\u6362 <code>NULL<\/code>\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u793a\u4f8b\uff1a<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>-- \u67e5\u8be2\u4e3a NULL \u7684\u8bb0\u5f55\nSELECT * FROM users WHERE email IS NULL;\n\n-- \u7528\u9ed8\u8ba4\u503c\u66ff\u6362 NULL\nSELECT name, COALESCE(email, 'No Email') FROM users;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">6. <strong>\u95ee\u9898\uff1a\u67e5\u8be2\u590d\u6742\u5ea6\u9ad8\uff0c\u6548\u7387\u4f4e<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u539f\u56e0\uff1a<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">SQL\u67e5\u8be2\u6d89\u53ca\u590d\u6742\u7684 <code>JOIN<\/code> \u6216\u5b50\u67e5\u8be2\uff0c\u5bfc\u81f4\u67e5\u8be2\u6267\u884c\u6548\u7387\u4f4e\u4e0b\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4f7f\u7528 <code>JOIN<\/code> \u4ee3\u66ff\u5b50\u67e5\u8be2\uff1a<\/strong> \u5728\u5408\u9002\u7684\u60c5\u51b5\u4e0b\uff0c\u4f7f\u7528 <code>JOIN<\/code> \u8fde\u63a5\u8868\uff0c\u800c\u4e0d\u662f\u5728 <code>SELECT<\/code>\u3001<code>WHERE<\/code> \u5b50\u53e5\u4e2d\u4f7f\u7528\u5b50\u67e5\u8be2\u3002<\/li>\n\n\n\n<li><strong>\u4f7f\u7528\u9002\u5f53\u7684\u7d22\u5f15\uff1a<\/strong> \u786e\u4fdd\u5bf9\u5e38\u7528\u7684\u8fde\u63a5\u6761\u4ef6\u6216\u8fc7\u6ee4\u6761\u4ef6\u5217\u5efa\u7acb\u7d22\u5f15\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u793a\u4f8b\uff1a<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>-- \u4f7f\u7528 JOIN \u4ee3\u66ff\u5b50\u67e5\u8be2\nSELECT u.name, o.order_id\nFROM users u\nJOIN orders o ON u.user_id = o.user_id\nWHERE o.status = 'completed';<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">7. <strong>\u95ee\u9898\uff1a\u6ca1\u6709\u6570\u636e\u5907\u4efd<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u539f\u56e0\uff1a<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u6570\u636e\u5e93\u6ca1\u6709\u5b9a\u671f\u8fdb\u884c\u5907\u4efd\uff0c\u53ef\u80fd\u5728\u6570\u636e\u4e22\u5931\u6216\u707e\u96be\u6062\u590d\u65f6\u5bfc\u81f4\u6570\u636e\u65e0\u6cd5\u6062\u590d\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5b9a\u671f\u5907\u4efd\uff1a<\/strong> \u4f7f\u7528\u6570\u636e\u5e93\u7684\u5907\u4efd\u529f\u80fd\u5b9a\u671f\u8fdb\u884c\u5b8c\u6574\u5907\u4efd\u3001\u589e\u91cf\u5907\u4efd\u548c\u65e5\u5fd7\u5907\u4efd\u3002<\/li>\n\n\n\n<li><strong>\u6062\u590d\u6d4b\u8bd5\uff1a<\/strong> \u5b9a\u671f\u6d4b\u8bd5\u5907\u4efd\u7684\u6062\u590d\u8fc7\u7a0b\uff0c\u786e\u4fdd\u6062\u590d\u673a\u5236\u6709\u6548\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u793a\u4f8b\uff1a<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>-- \u5b8c\u5168\u5907\u4efd\u547d\u4ee4\uff08MySQL\u793a\u4f8b\uff09\nmysqldump -u root -p database_name &gt; backup.sql<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">8. <strong>\u95ee\u9898\uff1a\u672a\u8fdb\u884c\u6570\u636e\u9a8c\u8bc1\u548c\u6e05\u6d17<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u539f\u56e0\uff1a<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u8f93\u5165\u7684\u6570\u636e\u672a\u7ecf\u9a8c\u8bc1\u6216\u6e05\u6d17\uff0c\u5bfc\u81f4\u65e0\u6548\u3001\u6076\u610f\u6216\u9519\u8bef\u7684\u6570\u636e\u5199\u5165\u6570\u636e\u5e93\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4f7f\u7528\u6570\u636e\u7ea6\u675f\uff1a<\/strong> \u5229\u7528\u6570\u636e\u5e93\u7684 <code>NOT NULL<\/code>\u3001<code>CHECK<\/code>\u3001<code>UNIQUE<\/code> \u7b49\u7ea6\u675f\u8fdb\u884c\u6570\u636e\u9a8c\u8bc1\u3002<\/li>\n\n\n\n<li><strong>\u6570\u636e\u6e05\u6d17\uff1a<\/strong> \u5728\u5e94\u7528\u5c42\u5bf9\u6570\u636e\u8fdb\u884c\u683c\u5f0f\u68c0\u67e5\uff0c\u786e\u4fdd\u5176\u7b26\u5408\u9884\u671f\u683c\u5f0f\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u793a\u4f8b\uff1a<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>-- \u8bbe\u7f6e\u7ea6\u675f\u786e\u4fdd\u6570\u636e\u4e00\u81f4\u6027\nCREATE TABLE users (\n    id INT PRIMARY KEY,\n    name VARCHAR(255) NOT NULL,\n    email VARCHAR(255) UNIQUE,\n    age INT CHECK (age &gt; 0)\n);<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">9. <strong>\u95ee\u9898\uff1a\u9519\u8bef\u7684\u65e5\u671f\u6216\u65f6\u95f4\u683c\u5f0f<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u539f\u56e0\uff1a<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u5904\u7406\u65e5\u671f\u6216\u65f6\u95f4\u65f6\u683c\u5f0f\u4e0d\u4e00\u81f4\uff0c\u5bfc\u81f4\u6570\u636e\u9519\u8bef\u6216\u67e5\u8be2\u95ee\u9898\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4f7f\u7528\u6807\u51c6\u65e5\u671f\u683c\u5f0f\uff1a<\/strong> \u4f7f\u7528\u6570\u636e\u5e93\u652f\u6301\u7684\u65e5\u671f\u7c7b\u578b\uff0c\u5982 <code>DATE<\/code>\u3001<code>DATETIME<\/code> \u6216 <code>TIMESTAMP<\/code>\u3002<\/li>\n\n\n\n<li><strong>\u7edf\u4e00\u65f6\u533a\uff1a<\/strong> \u5b58\u50a8\u548c\u5904\u7406\u6570\u636e\u65f6\uff0c\u4f7f\u7528\u7edf\u4e00\u7684\u65f6\u533a\uff08\u5982UTC\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u793a\u4f8b\uff1a<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>-- \u4f7f\u7528\u6807\u51c6\u65e5\u671f\u683c\u5f0f\nCREATE TABLE events (\n    event_id INT PRIMARY KEY,\n    event_name VARCHAR(255),\n    event_date DATE\n);\n\n-- \u63d2\u5165\u65e5\u671f\u6570\u636e\nINSERT INTO events (event_id, event_name, event_date) \nVALUES (1, 'Launch Event', '2025-02-10');<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">10. <strong>\u95ee\u9898\uff1a\u67e5\u8be2\u8fd4\u56de\u8fc7\u591a\u6570\u636e<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u539f\u56e0\uff1a<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u67e5\u8be2\u6ca1\u6709\u9650\u5236\u8fd4\u56de\u7ed3\u679c\uff0c\u5bfc\u81f4\u67e5\u8be2\u8fd4\u56de\u7684\u6570\u636e\u91cf\u8fc7\u5927\uff0c\u5f71\u54cd\u6027\u80fd\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4f7f\u7528 <code>LIMIT<\/code> \u9650\u5236\u8fd4\u56de\u6570\u636e\u91cf\uff1a<\/strong> \u5728\u67e5\u8be2\u4e2d\u4f7f\u7528 <code>LIMIT<\/code> \u6216 <code>OFFSET<\/code> \u9650\u5236\u8fd4\u56de\u7684\u884c\u6570\uff0c\u5c24\u5176\u662f\u5728\u5206\u9875\u67e5\u8be2\u65f6\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u793a\u4f8b\uff1a<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>-- \u5206\u9875\u67e5\u8be2\uff0c\u8fd4\u56de\u524d20\u6761\u8bb0\u5f55\nSELECT * FROM users LIMIT 20 OFFSET 0;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">11. <strong>\u95ee\u9898\uff1a\u6570\u636e\u63d2\u5165\u65f6\u91cd\u590d\u8bb0\u5f55<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u539f\u56e0\uff1a<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u63d2\u5165\u6570\u636e\u65f6\uff0c\u672a\u8003\u8651\u5230\u6570\u636e\u552f\u4e00\u6027\uff0c\u5bfc\u81f4\u91cd\u590d\u8bb0\u5f55\u7684\u63d2\u5165\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4f7f\u7528\u552f\u4e00\u7ea6\u675f\uff08<code>UNIQUE<\/code>\uff09\uff1a<\/strong> \u786e\u4fdd\u8868\u4e2d\u67d0\u4e9b\u5217\u7684\u6570\u636e\u552f\u4e00\uff0c\u9632\u6b62\u63d2\u5165\u91cd\u590d\u6570\u636e\u3002<\/li>\n\n\n\n<li><strong>\u4f7f\u7528 <code>INSERT IGNORE<\/code> \u6216 <code>ON DUPLICATE KEY UPDATE<\/code>\uff1a<\/strong> \u5f53\u5c1d\u8bd5\u63d2\u5165\u91cd\u590d\u6570\u636e\u65f6\uff0c\u5ffd\u7565\u6216\u66f4\u65b0\u73b0\u6709\u8bb0\u5f55\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u793a\u4f8b\uff1a<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>-- \u521b\u5efa\u552f\u4e00\u7ea6\u675f\nCREATE TABLE users (\n    id INT PRIMARY KEY,\n    email VARCHAR(255) UNIQUE\n);\n\n-- \u4f7f\u7528 INSERT IGNORE \u9632\u6b62\u91cd\u590d\u63d2\u5165\nINSERT IGNORE INTO users (id, email) VALUES (1, 'user@example.com');\n\n-- \u4f7f\u7528 ON DUPLICATE KEY UPDATE \u66f4\u65b0\u91cd\u590d\u6570\u636e\nINSERT INTO users (id, email) VALUES (1, 'user@example.com')\nON DUPLICATE KEY UPDATE email = 'user@example.com';<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">12. <strong>\u95ee\u9898\uff1a\u5fd8\u8bb0\u63d0\u4ea4\u4e8b\u52a1<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u539f\u56e0\uff1a<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u4f7f\u7528\u4e8b\u52a1\u65f6\u5fd8\u8bb0\u6267\u884c <code>COMMIT<\/code>\uff0c\u5bfc\u81f4\u6570\u636e\u53d8\u66f4\u6ca1\u6709\u6301\u4e45\u5316\u5230\u6570\u636e\u5e93\uff0c\u6216\u8005\u4e8b\u52a1\u4fdd\u6301\u6253\u5f00\u72b6\u6001\uff0c\u963b\u585e\u5176\u4ed6\u64cd\u4f5c\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u786e\u4fdd\u5728\u4e8b\u52a1\u7ed3\u675f\u65f6\u4f7f\u7528 <code>COMMIT<\/code>\uff1a<\/strong> \u4f7f\u7528\u4e8b\u52a1\u65f6\uff0c\u786e\u4fdd\u6240\u6709\u64cd\u4f5c\u5b8c\u6210\u540e\u8c03\u7528 <code>COMMIT<\/code>\uff0c\u5982\u679c\u53d1\u751f\u9519\u8bef\uff0c\u4f7f\u7528 <code>ROLLBACK<\/code> \u8fdb\u884c\u56de\u6eda\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u793a\u4f8b\uff1a<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>-- \u4f7f\u7528\u4e8b\u52a1\nBEGIN;\n\nUPDATE accounts SET balance = balance - 100 WHERE user_id = 1;\nUPDATE accounts SET balance = balance + 100 WHERE user_id = 2;\n\n-- \u786e\u4fdd\u63d0\u4ea4\u4e8b\u52a1\nCOMMIT;\n\n-- \u5982\u679c\u53d1\u751f\u9519\u8bef\uff0c\u53ef\u4ee5\u4f7f\u7528 ROLLBACK\nROLLBACK;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">13. <strong>\u95ee\u9898\uff1a\u6570\u636e\u7c7b\u578b\u4e0d\u5339\u914d<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u539f\u56e0\uff1a<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u63d2\u5165\u6570\u636e\u65f6\uff0c\u6570\u636e\u7684\u7c7b\u578b\u4e0e\u8868\u4e2d\u5b57\u6bb5\u7684\u7c7b\u578b\u4e0d\u5339\u914d\uff0c\u5bfc\u81f4\u63d2\u5165\u5931\u8d25\u6216\u9519\u8bef\u6570\u636e\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u786e\u4fdd\u63d2\u5165\u7684\u6570\u636e\u7c7b\u578b\u4e0e\u5b57\u6bb5\u7c7b\u578b\u4e00\u81f4\uff1a<\/strong> \u5728\u63d2\u5165\u6570\u636e\u65f6\uff0c\u786e\u8ba4\u6bcf\u5217\u7684\u6570\u636e\u7c7b\u578b\u4e0e\u8868\u5b9a\u4e49\u76f8\u7b26\u3002<\/li>\n\n\n\n<li><strong>\u4f7f\u7528\u7c7b\u578b\u8f6c\u6362\u51fd\u6570\uff1a<\/strong> \u5728\u63d2\u5165\u65f6\u4f7f\u7528 <code>CAST<\/code> \u6216 <code>CONVERT<\/code> \u6765\u8f6c\u6362\u6570\u636e\u7c7b\u578b\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u793a\u4f8b\uff1a<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>-- \u63d2\u5165\u6574\u6570\u65f6\u7c7b\u578b\u4e0d\u5339\u914d\u7684\u60c5\u51b5\nINSERT INTO users (age) VALUES ('30');  -- \u9519\u8bef\n\n-- \u4f7f\u7528\u7c7b\u578b\u8f6c\u6362\u51fd\u6570\u8fdb\u884c\u6570\u636e\u7c7b\u578b\u8f6c\u6362\nINSERT INTO users (age) VALUES (CAST('30' AS INT));  -- \u6b63\u786e<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">14. <strong>\u95ee\u9898\uff1a\u4e0d\u4f7f\u7528\u5408\u9002\u7684\u4e8b\u52a1\u9694\u79bb\u7ea7\u522b<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u539f\u56e0\uff1a<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0d\u540c\u7684\u4e8b\u52a1\u9694\u79bb\u7ea7\u522b\u4f1a\u5f71\u54cd\u5e76\u53d1\u63a7\u5236\uff0c\u5bfc\u81f4\u810f\u8bfb\u3001\u4e0d\u53ef\u91cd\u590d\u8bfb\u6216\u5e7b\u8bfb\u7b49\u95ee\u9898\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u9009\u62e9\u9002\u5f53\u7684\u4e8b\u52a1\u9694\u79bb\u7ea7\u522b\uff1a<\/strong> \u6839\u636e\u5e94\u7528\u573a\u666f\u9009\u62e9\u5408\u9002\u7684\u4e8b\u52a1\u9694\u79bb\u7ea7\u522b\u3002\n<ul class=\"wp-block-list\">\n<li><code>READ COMMITTED<\/code>\uff1a\u9632\u6b62\u810f\u8bfb\u3002<\/li>\n\n\n\n<li><code>REPEATABLE READ<\/code>\uff1a\u9632\u6b62\u810f\u8bfb\u548c\u4e0d\u53ef\u91cd\u590d\u8bfb\u3002<\/li>\n\n\n\n<li><code>SERIALIZABLE<\/code>\uff1a\u9632\u6b62\u810f\u8bfb\u3001\u4e0d\u53ef\u91cd\u590d\u8bfb\u548c\u5e7b\u8bfb\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u793a\u4f8b\uff1a<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>-- \u8bbe\u7f6e\u4e8b\u52a1\u9694\u79bb\u7ea7\u522b\u4e3a READ COMMITTED\nSET TRANSACTION ISOLATION LEVEL READ COMMITTED;\n\nBEGIN;\nSELECT * FROM accounts WHERE user_id = 1;\nUPDATE accounts SET balance = balance - 100 WHERE user_id = 1;\nCOMMIT;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">15. <strong>\u95ee\u9898\uff1a\u9519\u8bef\u7684\u8868\u8fde\u63a5\u5bfc\u81f4\u91cd\u590d\u8bb0\u5f55<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u539f\u56e0\uff1a<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><code>JOIN<\/code> \u64cd\u4f5c\u65f6\uff0c\u5982\u679c\u8fde\u63a5\u6761\u4ef6\u4e0d\u6b63\u786e\uff0c\u53ef\u80fd\u5bfc\u81f4\u67e5\u8be2\u7ed3\u679c\u4e2d\u91cd\u590d\u7684\u8bb0\u5f55\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u786e\u4fdd\u8fde\u63a5\u6761\u4ef6\u51c6\u786e\uff1a<\/strong> \u4f7f\u7528\u6b63\u786e\u7684 <code>ON<\/code> \u5b50\u53e5\u6765\u8fde\u63a5\u8868\uff0c\u907f\u514d\u65e0\u610f\u95f4\u4ea7\u751f\u91cd\u590d\u884c\u3002<\/li>\n\n\n\n<li><strong>\u4f7f\u7528 <code>DISTINCT<\/code> \u53bb\u91cd\uff1a<\/strong> \u5982\u679c\u67e5\u8be2\u7ed3\u679c\u5305\u542b\u91cd\u590d\u8bb0\u5f55\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>DISTINCT<\/code> \u6765\u53bb\u91cd\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u793a\u4f8b\uff1a<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>-- \u9519\u8bef\u7684\u8fde\u63a5\u6761\u4ef6\uff0c\u53ef\u80fd\u5bfc\u81f4\u91cd\u590d\u8bb0\u5f55\nSELECT orders.order_id, users.name FROM orders\nJOIN users ON orders.user_id = users.user_id;\n\n-- \u4f7f\u7528 DISTINCT \u53bb\u91cd\nSELECT DISTINCT orders.order_id, users.name FROM orders\nJOIN users ON orders.user_id = users.user_id;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">16. <strong>\u95ee\u9898\uff1a\u4e0d\u5904\u7406 NULL \u503c\u7684\u805a\u5408\u51fd\u6570<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u539f\u56e0\uff1a<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f7f\u7528\u805a\u5408\u51fd\u6570\uff08\u5982 <code>SUM<\/code>\u3001<code>AVG<\/code>\uff09\u65f6\uff0c\u672a\u8003\u8651 <code>NULL<\/code> \u503c\uff0c\u53ef\u80fd\u5bfc\u81f4\u8ba1\u7b97\u7ed3\u679c\u9519\u8bef\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4f7f\u7528 <code>COALESCE<\/code> \u6216 <code>IFNULL<\/code> \u66ff\u6362 <code>NULL<\/code>\uff1a<\/strong> \u5728\u8fdb\u884c\u805a\u5408\u8ba1\u7b97\u65f6\uff0c\u786e\u4fdd <code>NULL<\/code> \u503c\u4e0d\u4f1a\u5f71\u54cd\u7ed3\u679c\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u793a\u4f8b\uff1a<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>-- \u805a\u5408\u51fd\u6570\u4f1a\u5ffd\u7565 NULL \u503c\uff0c\u4f46\u4f7f\u7528 COALESCE \u5904\u7406\nSELECT SUM(COALESCE(salary, 0)) FROM employees;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">17. <strong>\u95ee\u9898\uff1a\u4e0d\u4f7f\u7528\u9002\u5f53\u7684\u805a\u5408\u548c\u5206\u7ec4\u6761\u4ef6<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u539f\u56e0\uff1a<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u4f7f\u7528 <code>GROUP BY<\/code> \u65f6\uff0c\u6ca1\u6709\u9002\u5f53\u7684\u5206\u7ec4\u6761\u4ef6\uff0c\u53ef\u80fd\u5bfc\u81f4\u67e5\u8be2\u7ed3\u679c\u4e0d\u51c6\u786e\u6216\u4ea7\u751f\u9519\u8bef\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u786e\u4fdd\u6b63\u786e\u4f7f\u7528 <code>GROUP BY<\/code> \u548c\u805a\u5408\u51fd\u6570\uff1a<\/strong> \u805a\u5408\u5b57\u6bb5\u5e94\u5f53\u5728 <code>GROUP BY<\/code> \u5b50\u53e5\u4e2d\u5217\u51fa\uff0c\u786e\u4fdd\u6309\u9884\u671f\u5206\u7ec4\u6570\u636e\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u793a\u4f8b\uff1a<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>-- \u9519\u8bef\u7684\u67e5\u8be2\uff0cGROUP BY \u7684\u5b57\u6bb5\u6ca1\u6709\u5305\u62ec\u5728 SELECT \u4e2d\nSELECT department, AVG(salary) FROM employees;\n\n-- \u6b63\u786e\u7684\u67e5\u8be2\uff0cGROUP BY \u7684\u5b57\u6bb5\u5305\u62ec\u5728 SELECT \u4e2d\nSELECT department, AVG(salary) FROM employees GROUP BY department;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">18. <strong>\u95ee\u9898\uff1a\u66f4\u65b0\/\u5220\u9664\u65f6\u9057\u6f0f WHERE \u5b50\u53e5<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u539f\u56e0\uff1a<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u6267\u884c <code>UPDATE<\/code> \u6216 <code>DELETE<\/code> \u64cd\u4f5c\u65f6\uff0c\u5982\u679c\u9057\u6f0f\u4e86 <code>WHERE<\/code> \u5b50\u53e5\uff0c\u53ef\u80fd\u4f1a\u9519\u8bef\u5730\u66f4\u65b0\u6216\u5220\u9664\u6240\u6709\u8bb0\u5f55\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u59cb\u7ec8\u4f7f\u7528 <code>WHERE<\/code> \u5b50\u53e5\uff1a<\/strong> \u5728\u6267\u884c\u66f4\u65b0\u6216\u5220\u9664\u64cd\u4f5c\u65f6\uff0c\u786e\u4fdd\u5bf9\u7279\u5b9a\u8bb0\u5f55\u8fdb\u884c\u64cd\u4f5c\uff0c\u907f\u514d\u610f\u5916\u4fee\u6539\u6216\u5220\u9664\u6240\u6709\u6570\u636e\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u793a\u4f8b\uff1a<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>-- \u9519\u8bef\u7684 UPDATE\uff0c\u672a\u4f7f\u7528 WHERE \u5b50\u53e5\nUPDATE users SET age = 30;  -- \u8fd9\u4f1a\u66f4\u65b0\u6240\u6709\u8bb0\u5f55\n\n-- \u6b63\u786e\u7684 UPDATE\uff0c\u4f7f\u7528 WHERE \u5b50\u53e5\nUPDATE users SET age = 30 WHERE user_id = 1;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">19. <strong>\u95ee\u9898\uff1a\u5904\u7406\u5927\u6570\u636e\u96c6\u65f6\u7684\u5185\u5b58\u6d88\u8017\u8fc7\u5927<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u539f\u56e0\uff1a<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u67e5\u8be2\u5927\u578b\u6570\u636e\u96c6\u65f6\u6ca1\u6709\u505a\u9002\u5f53\u7684\u6570\u636e\u5206\u9875\u6216\u5206\u6279\u5904\u7406\uff0c\u5bfc\u81f4\u5185\u5b58\u6d88\u8017\u8fc7\u9ad8\uff0c\u5f71\u54cd\u7cfb\u7edf\u6027\u80fd\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5206\u9875\u67e5\u8be2\uff1a<\/strong> \u4f7f\u7528 <code>LIMIT<\/code> \u6216 <code>OFFSET<\/code> \u6765\u5206\u6279\u5904\u7406\u67e5\u8be2\uff0c\u907f\u514d\u4e00\u6b21\u6027\u52a0\u8f7d\u8fc7\u591a\u6570\u636e\u3002<\/li>\n\n\n\n<li><strong>\u4f18\u5316\u6570\u636e\u63d0\u53d6\uff1a<\/strong> \u5bf9\u5927\u6570\u636e\u96c6\u8fdb\u884c\u5206\u5757\u67e5\u8be2\uff0c\u786e\u4fdd\u7cfb\u7edf\u5185\u5b58\u8db3\u591f\u5904\u7406\u6bcf\u4e2a\u67e5\u8be2\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u793a\u4f8b\uff1a<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>-- \u5206\u6279\u67e5\u8be2\u6570\u636e\nSELECT * FROM users LIMIT 100 OFFSET 0;\nSELECT * FROM users LIMIT 100 OFFSET 100;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">20. <strong>\u95ee\u9898\uff1a\u9519\u8bef\u7684\u6570\u636e\u6a21\u578b\u8bbe\u8ba1<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u539f\u56e0\uff1a<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u6570\u636e\u5e93\u8bbe\u8ba1\u4e0d\u5408\u7406\uff0c\u53ef\u80fd\u5bfc\u81f4\u6570\u636e\u5197\u4f59\u3001\u67e5\u8be2\u6027\u80fd\u5dee\u3001\u6570\u636e\u4e0d\u4e00\u81f4\u7b49\u95ee\u9898\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4f7f\u7528\u89c4\u8303\u5316\uff08Normalization\uff09\uff1a<\/strong> \u786e\u4fdd\u6570\u636e\u5e93\u8bbe\u8ba1\u7b26\u5408\u89c4\u8303\u5316\u89c4\u5219\uff08\u81f3\u5c11\u7b2c\u4e09\u8303\u5f0f\uff09\uff0c\u907f\u514d\u6570\u636e\u5197\u4f59\u3002<\/li>\n\n\n\n<li><strong>\u5408\u7406\u8bbe\u8ba1\u8868\u4e0e\u5173\u7cfb\uff1a<\/strong> \u8bbe\u8ba1\u9002\u5f53\u7684\u8868\u7ed3\u6784\uff0c\u786e\u4fdd\u8868\u4e4b\u95f4\u7684\u5173\u7cfb\u6e05\u6670\uff0c\u907f\u514d\u5faa\u73af\u4f9d\u8d56\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u793a\u4f8b\uff1a<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>-- \u9519\u8bef\u7684\u6570\u636e\u5e93\u8bbe\u8ba1\uff1a\u91cd\u590d\u5b58\u50a8\u76f8\u540c\u4fe1\u606f\nCREATE TABLE orders (\n    order_id INT PRIMARY KEY,\n    user_name VARCHAR(255),\n    user_email VARCHAR(255)\n);\n\n-- \u6539\u8fdb\u540e\u7684\u8bbe\u8ba1\uff1a\u5c06\u7528\u6237\u4fe1\u606f\u79fb\u81f3\u72ec\u7acb\u8868\nCREATE TABLE users (\n    user_id INT PRIMARY KEY,\n    name VARCHAR(255),\n    email VARCHAR(255) UNIQUE\n);\n\nCREATE TABLE orders (\n    order_id INT PRIMARY KEY,\n    user_id INT,\n    FOREIGN KEY (user_id) REFERENCES users(user_id)\n);<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u603b\u7ed3\uff1a<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e9b\u5e38\u89c1\u7684SQL\u95ee\u9898\u53ca\u89e3\u51b3\u65b9\u6cd5\u6db5\u76d6\u4e86\u4ece\u6570\u636e\u63d2\u5165\u3001\u67e5\u8be2\u4f18\u5316\u5230\u6570\u636e\u5e93\u8bbe\u8ba1\u7b49\u591a\u4e2a\u65b9\u9762\u3002\u4e86\u89e3\u5e76\u89e3\u51b3\u8fd9\u4e9b\u95ee\u9898\u5c06\u5e2e\u52a9\u5f00\u53d1\u8005\u63d0\u9ad8SQL\u67e5\u8be2\u6548\u7387\uff0c\u4fdd\u8bc1\u6570\u636e\u7684\u51c6\u786e\u6027\uff0c\u5e76\u4f18\u5316\u6570\u636e\u5e93\u7684\u6574\u4f53\u6027\u80fd\u3002\u901a\u8fc7\u4e0d\u65ad\u7684\u5b9e\u8df5\u548c\u8c03\u6574\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\u6709\u6548\u89e3\u51b3\u8fd9\u4e9b\u95ee\u9898\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u4f7f\u7528SQL\u65f6\uff0c\u5f00\u53d1\u8005\u5e38\u5e38\u4f1a\u9047\u5230\u5404\u79cd\u95ee\u9898\uff0c\u5f71\u54cd\u67e5\u8be2\u6548\u7387\u3001\u6570\u636e\u4e00\u81f4\u6027\u6216\u7cfb\u7edf\u6027\u80fd\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684SQL\u95ee\u9898\u53ca\u5176\u89e3 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"class_list":["post-1528","post","type-post","status-publish","format-standard","hentry","category-sql"],"_links":{"self":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/1528","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/comments?post=1528"}],"version-history":[{"count":1,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/1528\/revisions"}],"predecessor-version":[{"id":1529,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/1528\/revisions\/1529"}],"wp:attachment":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/media?parent=1528"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/categories?post=1528"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/tags?post=1528"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}