共計 1472 個字符,預計需要花費 4 分鐘才能閱讀完成。
自動寫代碼機器人,免費開通
這篇文章主要介紹“Oracle 和 MySQL 怎么給表添加注釋”,在日常操作中,相信很多人在 Oracle 和 MySQL 怎么給表添加注釋問題上存在疑惑,丸趣 TV 小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”Oracle 和 MySQL 怎么給表添加注釋”的疑惑有所幫助!接下來,請跟著丸趣 TV 小編一起來學習吧!
在 MySQL 和 oracle 數據庫中,字段或列的注釋是用屬性 comment 來添加。創建新表的腳本中,可在字段定義腳本中添加 comment 屬性來添加注釋。下面就來介紹添加注釋的方法,有需要的可以參考一下。
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
到此,關于“Oracle 和 MySQL 怎么給表添加注釋”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續學習更多相關知識,請繼續關注丸趣 TV 網站,丸趣 TV 小編會繼續努力為大家帶來更多實用的文章!
向 AI 問一下細節