{"id":5768,"date":"2024-11-14T09:04:44","date_gmt":"2024-11-14T01:04:44","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5768\/"},"modified":"2024-11-14T09:04:44","modified_gmt":"2024-11-14T01:04:44","slug":"mysql%e4%b8%adcomment%e4%bb%80%e4%b9%88%e6%84%8f%e6%80%9d","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5768\/","title":{"rendered":"mysql\u4e2dcomment\u4ec0\u4e48\u610f\u601d"},"content":{"rendered":"<blockquote><p>\n  mysql \u4e2d\u7684 comment \u5173\u952e\u5b57\u7528\u4e8e\u4e3a\u6570\u636e\u5e93\u5bf9\u8c61\u6dfb\u52a0\u6ce8\u91ca\u6216\u63cf\u8ff0\u4fe1\u606f\uff0c\u4ee5\u6587\u6863\u5316\u5bf9\u8c61\u5e76\u8f85\u52a9\u67e5\u8be2\u4f18\u5316\u3002\u53ef\u901a\u8fc7 alter object_type object_name comment &#8216;\u6ce8\u91ca\u5185\u5bb9&#8217; \u8bed\u6cd5\u6dfb\u52a0 comment\uff0c\u901a\u8fc7 show create table \u6216 information_schema.columns \u8868\u67e5\u770b\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/02\/2024060201035573292.jpg\" class=\"aligncenter\" title=\"mysql\u4e2dcomment\u4ec0\u4e48\u610f\u601d\u63d2\u56fe\" alt=\"mysql\u4e2dcomment\u4ec0\u4e48\u610f\u601d\u63d2\u56fe\" \/><\/p>\n<p><strong>MySQL \u4e2d\u7684 COMMENT<\/strong><\/p>\n<p><strong>COMMENT \u662f\u4ec0\u4e48\uff1f<\/strong><\/p>\n<p>COMMENT \u662f MySQL \u4e2d\u4e00\u4e2a\u5173\u952e\u5b57\uff0c\u7528\u4e8e\u4e3a\u6570\u636e\u5e93\u5bf9\u8c61\uff08\u5982\u8868\u3001\u5217\u3001\u89e6\u53d1\u5668\u7b49\uff09\u6dfb\u52a0\u6ce8\u91ca\u6216\u63cf\u8ff0\u4fe1\u606f\u3002<\/p>\n<p><strong>\u4f5c\u7528<\/strong><\/p>\n<p>COMMENT \u7684\u4f5c\u7528\u4e3b\u8981\u6709\u4e24\u4e2a\uff1a<\/p>\n<ul>\n<li> <strong>\u6587\u6863\u5316\uff1a<\/strong>\u4e3a\u5bf9\u8c61\u63d0\u4f9b\u6613\u4e8e\u7406\u89e3\u7684\u63cf\u8ff0\uff0c\u65b9\u4fbf\u5f00\u53d1\u4eba\u5458\u7406\u89e3\u6570\u636e\u5e93\u7ed3\u6784\u548c\u529f\u80fd\u3002<\/li>\n<li> <strong>\u67e5\u8be2\u4f18\u5316\uff1a<\/strong>\u901a\u8fc7 EXPLAIN \u67e5\u8be2\u8bed\u53e5\uff0c\u53ef\u4ee5\u770b\u5230\u5bf9\u8c61\u7684 COMMENT\uff0c\u6709\u52a9\u4e8e\u7406\u89e3\u67e5\u8be2\u8ba1\u5212\u5e76\u8fdb\u884c\u4f18\u5316\u3002<\/li>\n<\/ul>\n<p><strong>\u8bed\u6cd5<\/strong><\/p>\n<p>\u4e3a\u5bf9\u8c61\u6dfb\u52a0 COMMENT \u7684\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>ALTER OBJECT_TYPE OBJECT_NAME COMMENT '\u6ce8\u91ca\u5185\u5bb9';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff0cOBJECT_TYPE \u53ef\u4ee5\u662f TABLE\u3001COLUMN\u3001PROCEDURE \u7b49\uff0c\u800c OBJECT_NAME \u662f\u5bf9\u8c61\u540d\u79f0\u3002<\/p>\n<p><strong>\u4f7f\u7528\u793a\u4f8b<\/strong><\/p>\n<p>\u4f8b\u5982\uff0c\u4e3a &#8220;customers&#8221; \u8868\u6dfb\u52a0\u4e00\u4e2a\u6ce8\u91ca\uff1a<\/p>\n<pre>ALTER TABLE customers COMMENT '\u8fd9\u4e2a\u8868\u5b58\u50a8\u4e86\u5ba2\u6237\u4fe1\u606f';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4e3a &#8220;name&#8221; \u5217\u6dfb\u52a0\u4e00\u4e2a\u6ce8\u91ca\uff1a<\/p>\n<pre>ALTER TABLE customers ALTER COLUMN name COMMENT '\u5ba2\u6237\u540d\u79f0';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u67e5\u770b COMMENT<\/strong><\/p>\n<p>\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u6cd5\u67e5\u770b\u5bf9\u8c61\u7684 COMMENT\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528 SHOW CREATE TABLE \u8bed\u53e5\uff1a<\/li>\n<\/ul>\n<pre>SHOW CREATE TABLE customers;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li>\u4f7f\u7528 INFORMATION_SCHEMA.COLUMNS \u8868\uff1a<\/li>\n<\/ul>\n<pre>SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE, COMMENT\nFROM INFORMATION_SCHEMA.COLUMNS\nWHERE TABLE_SCHEMA = 'database_name' AND TABLE_NAME = 'table_name';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u4e2dcomment\u4ec0\u4e48\u610f\u601d\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>mysql \u4e2d\u7684 comment \u5173\u952e\u5b57\u7528\u4e8e\u4e3a\u6570\u636e\u5e93\u5bf9\u8c61\u6dfb\u52a0\u6ce8\u91ca\u6216\u63cf\u8ff0\u4fe1\u606f\uff0c\u4ee5\u6587\u6863\u5316\u5bf9\u8c61\u5e76\u8f85\u52a9\u67e5\u8be2\u4f18\u5316\u3002\u53ef\u901a\u8fc7 alter object_type object_name comment &#8216;\u6ce8\u91ca\u5185\u5bb9&#8217; \u8bed\u6cd5\u6dfb\u52a0 comment\uff0c\u901a\u8fc7 show create table \u6216 information_schema.columns \u8868\u67e5\u770b\u3002 MySQL \u4e2d\u7684 COMMENT COMMENT \u662f\u4ec0\u4e48\uff1f COMMENT \u662f MySQL \u4e2d\u4e00\u4e2a\u5173\u952e\u5b57\uff0c\u7528\u4e8e\u4e3a\u6570\u636e\u5e93\u5bf9\u8c61\uff08\u5982\u8868\u3001\u5217\u3001\u89e6\u53d1\u5668\u7b49\uff09\u6dfb\u52a0\u6ce8\u91ca\u6216\u63cf\u8ff0\u4fe1\u606f\u3002 \u4f5c\u7528 COMMENT \u7684\u4f5c\u7528\u4e3b\u8981\u6709\u4e24\u4e2a\uff1a \u6587\u6863\u5316\uff1a\u4e3a\u5bf9\u8c61\u63d0\u4f9b\u6613\u4e8e\u7406\u89e3\u7684\u63cf\u8ff0\uff0c\u65b9\u4fbf\u5f00\u53d1\u4eba\u5458\u7406\u89e3\u6570\u636e\u5e93\u7ed3\u6784\u548c\u529f\u80fd\u3002 \u67e5\u8be2\u4f18\u5316\uff1a\u901a\u8fc7 EXPLAIN \u67e5\u8be2\u8bed\u53e5\uff0c\u53ef\u4ee5\u770b\u5230\u5bf9\u8c61\u7684 COMMENT\uff0c\u6709\u52a9\u4e8e\u7406\u89e3\u67e5\u8be2\u8ba1\u5212\u5e76\u8fdb\u884c\u4f18\u5316\u3002 \u8bed\u6cd5 \u4e3a\u5bf9\u8c61\u6dfb\u52a0 COMMENT \u7684\u8bed\u6cd5\u5982\u4e0b\uff1a ALTER OBJECT_TYPE OBJECT_NAME COMMENT &#8216;\u6ce8\u91ca\u5185\u5bb9&#8217;; \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff0cOBJECT_TYPE \u53ef\u4ee5\u662f TABLE\u3001COLUMN\u3001PROCEDURE \u7b49\uff0c\u800c OBJECT_NAME \u662f\u5bf9\u8c61\u540d\u79f0\u3002 \u4f7f\u7528\u793a\u4f8b \u4f8b\u5982\uff0c\u4e3a &#8220;customers&#8221; \u8868\u6dfb\u52a0\u4e00\u4e2a\u6ce8\u91ca\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-5768","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5768","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=5768"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5768\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5768"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5768"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5768"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}