{"id":5614,"date":"2024-11-14T13:21:14","date_gmt":"2024-11-14T05:21:14","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5614\/"},"modified":"2024-11-14T13:21:14","modified_gmt":"2024-11-14T05:21:14","slug":"sql%e6%80%8e%e4%b9%88%e6%b7%bb%e5%8a%a0%e6%96%b0%e5%88%97","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5614\/","title":{"rendered":"sql\u600e\u4e48\u6dfb\u52a0\u65b0\u5217"},"content":{"rendered":"<p><strong>\u5982\u4f55\u4f7f\u7528 sql \u6dfb\u52a0\u65b0\u5217<\/strong><\/p>\n<p><strong>\u7b2c\u4e00\u6b65\uff1a\u786e\u5b9a\u8868\u540d<\/strong><\/p>\n<p>\u9996\u5148\uff0c\u786e\u5b9a\u8981\u6dfb\u52a0\u65b0\u5217\u7684\u8868\u540d\u3002<\/p>\n<p><strong>\u7b2c\u4e8c\u6b65\uff1a\u7f16\u5199 ALTER TABLE \u8bed\u53e5<\/strong><\/p>\n<p>\u4f7f\u7528 ALTER TABLE \u8bed\u53e5\u6dfb\u52a0\u65b0\u5217\u3002\u8bed\u53e5\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>ALTER TABLE table_name ADD column_name data_type [NOT NULL | NULL] [DEFAULT default_value]<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>table_name\uff1a\u8981\u6dfb\u52a0\u65b0\u5217\u7684\u8868\u7684\u540d\u79f0\u3002<\/li>\n<li>column_name\uff1a\u65b0\u5217\u7684\u540d\u79f0\u3002<\/li>\n<li>data_type\uff1a\u65b0\u5217\u7684\u6570\u636e\u7c7b\u578b\uff08\u4f8b\u5982\uff0cINT\u3001VARCHAR\u3001DATE\uff09\u3002<\/li>\n<li>NOT NULL: \u6307\u5b9a\u8be5\u5217\u4e0d\u80fd\u4e3a\u7a7a\u3002<\/li>\n<li>NULL: \u6307\u5b9a\u8be5\u5217\u53ef\u4ee5\u4e3a\u7a7a\u3002<\/li>\n<li>DEFAULT: \u6307\u5b9a\u8be5\u5217\u7684\u9ed8\u8ba4\u503c\uff08\u5982\u679c\u672a\u6307\u5b9a\uff0c\u5219\u9ed8\u8ba4\u4e3a NULL\uff09\u3002<\/li>\n<\/ul>\n<p><strong>\u7b2c\u4e09\u6b65\uff1a\u6267\u884c\u67e5\u8be2<\/strong><\/p>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u67e5\u8be2\u6267\u884c ALTER TABLE \u8bed\u53e5\uff1a<\/p>\n<pre>ALTER TABLE employees ADD salary INT NOT NULL DEFAULT 0;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4ee5\u4e0a\u67e5\u8be2\u5c06\u5728\u540d\u4e3a &#8220;employees&#8221; \u7684\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u540d\u4e3a &#8220;salary&#8221; \u7684\u65b0\u5217\uff0c\u5176\u6570\u636e\u7c7b\u578b\u4e3a INT\uff0c\u4e0d\u5141\u8bb8\u4e3a\u7a7a\uff0c\u9ed8\u8ba4\u503c\u4e3a 0\u3002<\/p>\n<p><strong>\u6ce8\u610f\u4e8b\u9879\uff1a<\/strong><\/p>\n<ul>\n<li>\u786e\u4fdd\u65b0\u5217\u7684\u540d\u79f0\u5728\u8be5\u8868\u4e2d\u552f\u4e00\u3002<\/li>\n<li>\u6570\u636e\u7c7b\u578b\u5fc5\u987b\u4e0e\u60a8\u8981\u5b58\u50a8\u7684\u6570\u636e\u517c\u5bb9\u3002<\/li>\n<li>\u5bf9\u4e8e\u4e0d\u5141\u8bb8\u4e3a\u7a7a\u7684\u5217\uff0c\u5fc5\u987b\u6307\u5b9a\u9ed8\u8ba4\u503c\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fsql\u600e\u4e48\u6dfb\u52a0\u65b0\u5217\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>\u5982\u4f55\u4f7f\u7528 sql \u6dfb\u52a0\u65b0\u5217 \u7b2c\u4e00\u6b65\uff1a\u786e\u5b9a\u8868\u540d \u9996\u5148\uff0c\u786e\u5b9a\u8981\u6dfb\u52a0\u65b0\u5217\u7684\u8868\u540d\u3002 \u7b2c\u4e8c\u6b65\uff1a\u7f16\u5199 ALTER TABLE \u8bed\u53e5 \u4f7f\u7528 ALTER TABLE \u8bed\u53e5\u6dfb\u52a0\u65b0\u5217\u3002\u8bed\u53e5\u8bed\u6cd5\u5982\u4e0b\uff1a ALTER TABLE table_name ADD column_name data_type [NOT NULL | NULL] [DEFAULT default_value] \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff1a table_name\uff1a\u8981\u6dfb\u52a0\u65b0\u5217\u7684\u8868\u7684\u540d\u79f0\u3002 column_name\uff1a\u65b0\u5217\u7684\u540d\u79f0\u3002 data_type\uff1a\u65b0\u5217\u7684\u6570\u636e\u7c7b\u578b\uff08\u4f8b\u5982\uff0cINT\u3001VARCHAR\u3001DATE\uff09\u3002 NOT NULL: \u6307\u5b9a\u8be5\u5217\u4e0d\u80fd\u4e3a\u7a7a\u3002 NULL: \u6307\u5b9a\u8be5\u5217\u53ef\u4ee5\u4e3a\u7a7a\u3002 DEFAULT: \u6307\u5b9a\u8be5\u5217\u7684\u9ed8\u8ba4\u503c\uff08\u5982\u679c\u672a\u6307\u5b9a\uff0c\u5219\u9ed8\u8ba4\u4e3a NULL\uff09\u3002 \u7b2c\u4e09\u6b65\uff1a\u6267\u884c\u67e5\u8be2 \u4f7f\u7528\u4ee5\u4e0b\u67e5\u8be2\u6267\u884c ALTER TABLE \u8bed\u53e5\uff1a ALTER TABLE employees ADD salary INT NOT NULL DEFAULT 0; \u767b\u5f55\u540e\u590d\u5236 \u4ee5\u4e0a\u67e5\u8be2\u5c06\u5728\u540d\u4e3a [&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-5614","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5614","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=5614"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5614\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5614"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5614"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5614"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}