首頁  >  文章  >  資料庫  >  Oracle和MySQL如何為表新增註釋

Oracle和MySQL如何為表新增註釋

醉折花枝作酒筹
醉折花枝作酒筹轉載
2021-07-22 09:12:483560瀏覽

在MySQL和oracle資料庫中,欄位或列的註解是用屬性comment來新增。建立新表格的腳本中, 可在欄位定義腳本中新增comment屬性來新增註解。下面就來介紹加入註解的方法,有需要的可以參考一下。

Oracle和MySQL如何為表新增註釋

Oracle新增註解(comment)

在Oracle資料庫中,欄位或列的註解是用屬性comment來新增。

1. 新增註解表:

comment on table 表名is '表格的註解內容';

實例程式碼如下:

 comment on table user is '用户表';

2. 在表格的欄位中新增註解:

comment on column 表格名稱.欄位名稱is '欄位註解';

實例程式碼如下:

comment on column user.username is '用户表中的用户名字段';

MySQL新增註解(comment)

在MySQL資料庫中,欄位或欄位的註解同樣也是用屬性comment來新增。

1.建立新表的腳本中, 可在欄位定義腳本中新增comment屬性來新增註解。

實例程式碼如下:

create table test( 
    id int not null default 0 comment '用户id' )

2.如果是已經建置好的表, 也可以用修改欄位的指令,然後加上comment屬性定義,就可以加入上註解了

實例程式碼如下:

alter table test 
change column id id int not null default 0 comment '测试表id'

檢視已有表格的所有欄位的註解呢?

可以用指令:show full columns from table 來查看, 範例如下:

show full columns from test;

建立表格的時候寫註解

create table test1 ( 
    field_name int comment '字段的注释' 
)comment='表的注释';

修改表格的註解

alter table test1 comment '修改后的表的注释';

修改欄位的註解

alter table test1 modify column field_name int comment '修改后的字段注释'; 

--注意:字段名和字段类型照写就行

檢視表格註解的方法

--在生成的SQL语句中看 
    show  create  table  test1; 
--在元数据的表里面看
    use information_schema; 
    select * from TABLES where TABLE_SCHEMA='my_db' and TABLE_NAME='test1' \G

#查看欄位註解的方法

--show 
    show  full  columns  from  test1; 
--在元数据的表里面看 
    select * from COLUMNS where TABLE_SCHEMA='my_db' and TABLE_NAME='test1' \G

相關推薦:《mysql教學

以上是Oracle和MySQL如何為表新增註釋的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:csdn.net。如有侵權,請聯絡admin@php.cn刪除