MySQL查詢備註資訊

2021-08-31 15:49:54 字數 1833 閱讀 7899

##在mysql下執行完下面這個建表語句後。 如何從資料字典中,檢索出這個表的字段的相關資訊?

drop table if exists test_table;

create table test_table(

test_id int not null auto_increment primary key comment '主鍵(自增長)',

test_key varchar(10) not null comment '種類',

test_value varchar(20) not null comment '數值',

test_type int not null comment '內部型別',

test_belongto int comment '從屬關係' ,

test_grade int default 1 comment '等級',

test_remark varchar(50) comment '備註',

test_visible bit default 1 comment '是否可見'

)comment = '測試表';

答案是:

select 

column_name as '列名',

data_type as '資料型別',

character_maximum_length as '字元長度',

numeric_precision as '數字長度',

numeric_scale as '小數字數',

is_nullable as '是否允許非空',

case

when extra = 'auto_increment' then 1

else 0

end as '是否自增',

column_default as '預設值',

column_comment as '備註'

from

information_schema.columns

where

table_name='test_table';

create table test1

( field_name int comment '欄位的注釋'

)comment='表的注釋';

2 修改表的注釋

alter table test1 comment '修改後的表的注釋';
3 修改欄位的注釋

-- 注意:欄位名和字段型別照寫就行

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

4 檢視表注釋的方法

-- 在生成的sql語句中看

show create table test1;

-- 在元資料的表裡面看

use information_schema;

select *

from tables

where table_schema='my_db' and table_name='test1'

5 檢視字段注釋的方法

-- show

show full columns from test1;

-- 在元資料的表裡面看

select * from columns where table_schema='my_db' and table_name='test1'

MySQL查詢以及修改表 表字段備註資訊

在開發中,我們可能經常碰到這種問題,隨著需求的變更,或者設計階段的失誤,表字段的長度太小,欄位的備註資訊需要完善。所以,就要更改表結構或者其它一些資訊了。話不多說,步入正題。建立測試表 create table student id int 11 primary key,name varchar 5...

Oracle 查詢表資訊(字段 備註)

獲取表字段 select from user tab columns where table name 使用者表 order by column name 獲取表注釋 select from user tab comments where table name 使用者表 order by table...

Oracle 查詢表資訊(字段 備註)

sql view plain copy 獲取表字段 select from user tab columns where table name 使用者表 order by column name 獲取表注釋 select from user tab comments where table name...