mysql怎么添加注釋

mysql添加注釋的方法:1、使用“alter table 表名 modify 字段名 類型 約束 comment ‘注釋內(nèi)容’;”語(yǔ)句為字段添加注釋;2、用“alter table 表名 comment ‘注釋內(nèi)容’;”語(yǔ)句為表添加注釋。

mysql怎么添加注釋

本教程操作環(huán)境:windows7系統(tǒng)、mysql8版本、Dell G3電腦。

MySql如何添加注釋

**在mysql數(shù)據(jù)庫(kù)中,數(shù)據(jù)庫(kù)表和字段的注釋用屬性comment來(lái)添加。*

1.為字段添加注釋:

1)創(chuàng)建新表時(shí),在表的字段約束后面添加注釋。

例如:

create?table?users(id?int(11)?primary?key?comment?‘用戶id’);

這里的users為表名,id為字段名,int(11)為類型,primary key為約束。

2)如果是已經(jīng)建好的表,可以用修改字段的命令,加上comment屬性。

例如:

alter?table?users?modify?name?varchar(20)not?NULL?comment?‘用戶名’;

這里的users為表名,name為字段名, varchar(20)為類型,not null 為約束。

2.為表添加注釋:

1)創(chuàng)建新表時(shí),在括號(hào)外面寫表注釋。

例如:

create?table?users?(?id?int(11)?primary?key?comment?'用戶id?')?comment=‘用戶信息表’;

2)已經(jīng)建好的表,可以修改表的時(shí)候加上注釋。

例如:

alter?table?users?comment?‘用戶信息表’;

這里的users為表名。

3.查看表注釋的方法

show?create?table?users;

這里users為表名。

4.查看字段注釋的方法

show?full?columns?from?users;

這里users為表名。

【相關(guān)推薦:mysql視頻教程

以上就是

? 版權(quán)聲明
THE END
喜歡就支持一下吧
點(diǎn)贊6 分享