{"id":25998,"date":"2024-11-24T15:47:32","date_gmt":"2024-11-24T07:47:32","guid":{"rendered":"https:\/\/fwq.ai\/blog\/25998\/"},"modified":"2024-11-24T15:47:32","modified_gmt":"2024-11-24T07:47:32","slug":"mysql-%e7%bb%88%e7%ab%af%ef%bc%9a%e6%b7%bb%e5%8a%a0%e5%92%8c%e5%88%a0%e9%99%a4%e5%88%97-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/25998\/","title":{"rendered":"MySQL \u7ec8\u7aef\uff1a\u6dfb\u52a0\u548c\u5220\u9664\u5217"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173077254321904.jpg\" class=\"aligncenter\" title=\"MySQL \u7ec8\u7aef\uff1a\u6dfb\u52a0\u548c\u5220\u9664\u5217\u63d2\u56fe\" alt=\"MySQL \u7ec8\u7aef\uff1a\u6dfb\u52a0\u548c\u5220\u9664\u5217\u63d2\u56fe\" \/><\/p>\n<h2> \u6dfb\u52a0\u5217 <\/h2>\n<p>sql \u4e2d\u7684 alter table &#8230; add column \u547d\u4ee4\u7528\u4e8e\u5411\u73b0\u6709\u8868\u6dfb\u52a0\u4e00\u5217\u6216\u591a\u5217\u3002\u4ee5\u4e0b\u662f\u6dfb\u52a0\u591a\u5217\u7684\u8bed\u6cd5\uff1a<\/p>\n<pre>alter table table_name \nadd column column_name1 data_type1 [options],\nadd column column_name2 data_type2 [options],\n...;\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/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\u60a8\u8981\u6dfb\u52a0\u7684\u6bcf\u4e2a\u65b0\u5217\u7684\u540d\u79f0\u3002<\/li>\n<li> data_type\uff1a\u6bcf\u4e2a\u65b0\u5217\u7684\u6570\u636e\u7c7b\u578b\u3002<\/li>\n<li> [options]\uff1a\u6bcf\u5217\u7684\u53ef\u9009\u8bbe\u7f6e\uff0c\u4f8b\u5982not null\u3001default\u503c\u7b49<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<p>\u5047\u8bbe\u60a8\u6709\u4e00\u4e2a\u540d\u4e3acustomers\u7684\u8868\uff0c\u5e76\u4e14\u60f3\u8981\u6dfb\u52a0\u4e24\u5217\uff1a\u7c7b\u578b\u4e3avarchar(255)\u7684\u7535\u5b50\u90ae\u4ef6\u548c\u7c7b\u578b\u4e3adate\u7684\u51fa\u751f\u65e5\u671f\u3002\u8be5\u547d\u4ee4\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>alter table customers \nadd column email varchar(255),\nadd column birth_date date;\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6b64\u547d\u4ee4\u4f1a\u5c06\u7535\u5b50\u90ae\u4ef6\u548cbirth_date \u5217\u6dfb\u52a0\u5230\u5ba2\u6237\u8868\u4e2d\u3002<\/p>\n<h2> \u5220\u9664\u5217 <\/h2>\n<p>sql \u4e2d\u7684 alter table &#8230; drop column \u547d\u4ee4\u7528\u4e8e\u4ece\u73b0\u6709\u8868\u4e2d\u5220\u9664\u5217\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>alter table table_name drop column column_name;\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li> table_name\uff1a\u8981\u4ece\u4e2d\u5220\u9664\u5217\u7684\u8868\u7684\u540d\u79f0\u3002<\/li>\n<li> column_name\uff1a\u8981\u5220\u9664\u7684\u5217\u7684\u540d\u79f0\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<p>\u5982\u679c\u60a8\u6709\u4e00\u4e2a\u540d\u4e3a\u201ccustomers\u201d\u7684\u8868\uff0c\u5e76\u4e14\u60f3\u8981\u5220\u9664\u540d\u4e3a\u201ceml\u201d\u7684\u5217\uff0c\u5219\u547d\u4ee4\u5c06\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>alter table customers drop column email;\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<blockquote><p>\n  \u8b66\u544a\uff1a\u5220\u9664\u5217\u662f\u4e00\u9879\u6c38\u4e45\u64cd\u4f5c\uff0c\u5c06\u5220\u9664\u8be5\u5217\u4e2d\u5b58\u50a8\u7684\u6240\u6709\u6570\u636e\u3002\n<\/p><\/blockquote>\n<p>\u6b64\u547d\u4ee4\u5c06\u4ece\u5ba2\u6237\u8868\u4e2d\u5220\u9664\u7535\u5b50\u90ae\u4ef6\u5217\u3002<\/p>\n<h2> \u4e4b\u540e\u6dfb\u52a0\u5217 <\/h2>\n<p>sql \u4e2d\u7684 alter table &#8230; add column &#8230; after \u547d\u4ee4\u7528\u4e8e\u5411\u73b0\u6709\u8868\u6dfb\u52a0\u4e00\u5217\u6216\u591a\u5217\uff0c\u6307\u5b9a\u65b0\u5217\u76f8\u5bf9\u4e8e\u73b0\u6709\u5217\u7684\u4f4d\u7f6e\u3002\u4ee5\u4e0b\u662f\u5728\u7279\u5b9a\u5217\u540e\u6dfb\u52a0\u591a\u5217\u7684\u8bed\u6cd5\uff1a<\/p>\n<pre>alter table table_name \nadd column column_name1 data_type1 [options] after existing_column_name,\nadd column column_name2 data_type2 [options] after existing_column_name,\n...;\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/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\u60a8\u8981\u6dfb\u52a0\u7684\u6bcf\u4e2a\u65b0\u5217\u7684\u540d\u79f0\u3002<\/li>\n<li> data_type\uff1a\u6bcf\u4e2a\u65b0\u5217\u7684\u6570\u636e\u7c7b\u578b\u3002<\/li>\n<li> \u73b0\u6709_\u5217_\u540d\u79f0\uff1a\u73b0\u6709\u5217\uff0c\u5c06\u5728\u5176\u540e\u6dfb\u52a0\u65b0\u5217\u3002<\/li>\n<li> [options]\uff1a\u6bcf\u5217\u7684\u4efb\u4f55\u53ef\u9009\u8bbe\u7f6e\uff0c\u4f8b\u5982 not null\u3001default \u503c\u7b49<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<p>\u5047\u8bbe\u60a8\u6709\u4e00\u4e2a\u540d\u4e3acustomers \u7684\u8868\uff0c\u5e76\u4e14\u60f3\u8981\u6dfb\u52a0\u4e24\u5217\uff0c\u7c7b\u578b\u4e3avarchar(255) \u7684email \u548c\u7c7b\u578b\u4e3adate \u7684birth_date\uff0c\u5e76\u5c06\u5b83\u4eec\u653e\u7f6e\u5728\u540d\u4e3aname \u7684\u73b0\u6709\u5217\u4e4b\u540e\u3002\u8be5\u547d\u4ee4\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>ALTER TABLE customers \nADD COLUMN email VARCHAR(255) AFTER name,\nADD COLUMN birth_date DATE AFTER name;\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6b64\u547d\u4ee4\u4f1a\u5c06\u7535\u5b50\u90ae\u4ef6\u548c\u51fa\u751f\u65e5\u671f\u5217\u6dfb\u52a0\u5230\u5ba2\u6237\u8868\u4e2d\uff0c\u5e76\u5c06\u5b83\u4eec\u653e\u7f6e\u5728\u540d\u79f0\u5217\u4e4b\u540e\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fMySQL \u7ec8\u7aef\uff1a\u6dfb\u52a0\u548c\u5220\u9664\u5217\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6dfb\u52a0\u5217 sql \u4e2d\u7684 alter table &#8230; add column \u547d\u4ee4\u7528\u4e8e\u5411\u73b0\u6709\u8868\u6dfb\u52a0\u4e00\u5217\u6216\u591a\u5217\u3002\u4ee5\u4e0b\u662f\u6dfb\u52a0\u591a\u5217\u7684\u8bed\u6cd5\uff1a alter table table_name add column column_name1 data_type1 [options], add column column_name2 data_type2 [options], &#8230;; \u767b\u5f55\u540e\u590d\u5236 table_name\uff1a\u8981\u6dfb\u52a0\u65b0\u5217\u7684\u8868\u7684\u540d\u79f0\u3002 column_name\uff1a\u60a8\u8981\u6dfb\u52a0\u7684\u6bcf\u4e2a\u65b0\u5217\u7684\u540d\u79f0\u3002 data_type\uff1a\u6bcf\u4e2a\u65b0\u5217\u7684\u6570\u636e\u7c7b\u578b\u3002 [options]\uff1a\u6bcf\u5217\u7684\u53ef\u9009\u8bbe\u7f6e\uff0c\u4f8b\u5982not null\u3001default\u503c\u7b49 \u793a\u4f8b \u5047\u8bbe\u60a8\u6709\u4e00\u4e2a\u540d\u4e3acustomers\u7684\u8868\uff0c\u5e76\u4e14\u60f3\u8981\u6dfb\u52a0\u4e24\u5217\uff1a\u7c7b\u578b\u4e3avarchar(255)\u7684\u7535\u5b50\u90ae\u4ef6\u548c\u7c7b\u578b\u4e3adate\u7684\u51fa\u751f\u65e5\u671f\u3002\u8be5\u547d\u4ee4\u5982\u4e0b\u6240\u793a\uff1a alter table customers add column email varchar(255), add column birth_date date; \u767b\u5f55\u540e\u590d\u5236 \u6b64\u547d\u4ee4\u4f1a\u5c06\u7535\u5b50\u90ae\u4ef6\u548cbirth_date \u5217\u6dfb\u52a0\u5230\u5ba2\u6237\u8868\u4e2d\u3002 \u5220\u9664\u5217 sql \u4e2d\u7684 alter table &#8230; drop column \u547d\u4ee4\u7528\u4e8e\u4ece\u73b0\u6709\u8868\u4e2d\u5220\u9664\u5217\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a alter [&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-25998","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25998","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=25998"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25998\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=25998"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=25998"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=25998"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}