{"id":5390,"date":"2024-11-14T10:45:22","date_gmt":"2024-11-14T02:45:22","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5390\/"},"modified":"2024-11-14T10:45:22","modified_gmt":"2024-11-14T02:45:22","slug":"mysql%e6%80%8e%e4%b9%88%e8%ae%be%e7%bd%ae%e9%bb%98%e8%ae%a4%e5%80%bc","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5390\/","title":{"rendered":"mysql\u600e\u4e48\u8bbe\u7f6e\u9ed8\u8ba4\u503c"},"content":{"rendered":"<blockquote><p>\n  \u4f7f\u7528 default \u5173\u952e\u5b57\u8bbe\u7f6e mysql \u4e2d\u5217\u7684\u9ed8\u8ba4\u503c\uff1a1. \u521b\u5efa\u8868\u65f6\u8bbe\u7f6e\u9ed8\u8ba4\u503c\uff1acreate table table_name (column_name data_type default default_value);2. \u4fee\u6539\u8868\u4e2d\u5217\u7684\u9ed8\u8ba4\u503c\uff1aalter table table_name alter column_name set default default_value;3. \u8bbe\u7f6e null \u4f5c\u4e3a\u9ed8\u8ba4\u503c\uff1acreate table table_name (column_name dat\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/28\/2024052810182314907.jpg\" class=\"aligncenter\" title=\"mysql\u600e\u4e48\u8bbe\u7f6e\u9ed8\u8ba4\u503c\u63d2\u56fe\" alt=\"mysql\u600e\u4e48\u8bbe\u7f6e\u9ed8\u8ba4\u503c\u63d2\u56fe\" \/><\/p>\n<p><strong>MySQL \u8bbe\u7f6e\u9ed8\u8ba4\u503c<\/strong><\/p>\n<p><strong>\u95ee\u9898\uff1a\u5982\u4f55\u8bbe\u7f6e MySQL \u4e2d\u5217\u7684\u9ed8\u8ba4\u503c\uff1f<\/strong><\/p>\n<p><strong>\u56de\u7b54\uff1a<\/strong>\u53ef\u4ee5\u4f7f\u7528 DEFAULT \u5173\u952e\u5b57\u6765\u8bbe\u7f6e MySQL \u4e2d\u5217\u7684\u9ed8\u8ba4\u503c\u3002<\/p>\n<p><strong>\u8be6\u7ec6\u6b65\u9aa4\uff1a<\/strong><\/p>\n<ol>\n<li><strong>\u521b\u5efa\u8868\u65f6\u8bbe\u7f6e\u9ed8\u8ba4\u503c\uff1a<\/strong><\/li>\n<\/ol>\n<pre>CREATE TABLE table_name (\n  column_name data_type DEFAULT default_value\n);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre>CREATE TABLE users (\n  id INT NOT NULL AUTO_INCREMENT,\n  name VARCHAR(255) DEFAULT 'Unknown'\n);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ol>\n<li><strong>\u4fee\u6539\u8868\u4e2d\u5217\u7684\u9ed8\u8ba4\u503c\uff1a<\/strong><\/li>\n<\/ol>\n<pre>ALTER TABLE table_name ALTER column_name SET DEFAULT default_value;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre>ALTER TABLE users ALTER name SET DEFAULT 'N\/A';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ol>\n<li><strong>\u8bbe\u7f6e NULL \u4f5c\u4e3a\u9ed8\u8ba4\u503c\uff1a<\/strong><\/li>\n<\/ol>\n<p>\u53ef\u4ee5\u4f7f\u7528 NULL \u5173\u952e\u5b57\u6765\u6307\u5b9a\u5217\u7684\u9ed8\u8ba4\u503c\u4e3a NULL\u3002<\/p>\n<pre>CREATE TABLE table_name (\n  column_name data_type DEFAULT NULL\n);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff1a<\/p>\n<ul>\n<li>\u9ed8\u8ba4\u503c\u53ea\u80fd\u5728\u8868\u521b\u5efa\u6216\u5217\u4fee\u6539\u65f6\u8bbe\u7f6e\u3002<\/li>\n<li>\u9ed8\u8ba4\u503c\u53ef\u4ee5\u662f\u5e38\u91cf\u3001\u8868\u8fbe\u5f0f\u6216\u51fd\u6570\u3002<\/li>\n<li>\u5982\u679c\u63d2\u5165\u7684\u6570\u636e\u672a\u6307\u5b9a\u503c\uff0c\u5219\u4f7f\u7528\u9ed8\u8ba4\u503c\u3002<\/li>\n<li>\u5bf9\u4e8e NOT NULL \u5217\uff0c\u5fc5\u987b\u8bbe\u7f6e\u9ed8\u8ba4\u503c\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u8bbe\u7f6e\u9ed8\u8ba4\u503c\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>\u4f7f\u7528 default \u5173\u952e\u5b57\u8bbe\u7f6e mysql \u4e2d\u5217\u7684\u9ed8\u8ba4\u503c\uff1a1. \u521b\u5efa\u8868\u65f6\u8bbe\u7f6e\u9ed8\u8ba4\u503c\uff1acreate table table_name (column_name data_type default default_value);2. \u4fee\u6539\u8868\u4e2d\u5217\u7684\u9ed8\u8ba4\u503c\uff1aalter table table_name alter column_name set default default_value;3. \u8bbe\u7f6e null \u4f5c\u4e3a\u9ed8\u8ba4\u503c\uff1acreate table table_name (column_name dat MySQL \u8bbe\u7f6e\u9ed8\u8ba4\u503c \u95ee\u9898\uff1a\u5982\u4f55\u8bbe\u7f6e MySQL \u4e2d\u5217\u7684\u9ed8\u8ba4\u503c\uff1f \u56de\u7b54\uff1a\u53ef\u4ee5\u4f7f\u7528 DEFAULT \u5173\u952e\u5b57\u6765\u8bbe\u7f6e MySQL \u4e2d\u5217\u7684\u9ed8\u8ba4\u503c\u3002 \u8be6\u7ec6\u6b65\u9aa4\uff1a \u521b\u5efa\u8868\u65f6\u8bbe\u7f6e\u9ed8\u8ba4\u503c\uff1a CREATE TABLE table_name ( column_name data_type DEFAULT default_value ); \u767b\u5f55\u540e\u590d\u5236 \u4f8b\u5982\uff1a CREATE TABLE users ( id [&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-5390","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5390","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=5390"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5390\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5390"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5390"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5390"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}