MySQL 查詢表結構簡單命令

2021-09-16 19:23:50 字數 2202 閱讀 5202

一、簡單描述表結構,字段型別

desc tabl_name;

顯示表結構,字段型別,主鍵,是否為空等屬性,但不顯示外來鍵。

例如:desc table_name

二、查詢表中列的注釋資訊

select * from information_schema.columns

where table_schema = 'db' #表所在資料庫

and table_name = 'tablename' ; #你要查的表

例如:

可以自動選擇你需要資訊

三、只查詢列名和注釋

select column_name, column_comment from information_schema.columns where table_schema ='db' and table_name = 'tablename' ;

例如:

四、#檢視表的注釋

select table_name,table_comment from information_schema.tables where table_schema = 'db' and table_name ='tablename'

例如:

五、檢視表生成的ddl

show create table table_name;

例如:

這個命令雖然顯示起來不是太容易看, 這個不是問題可以用\g來結尾,使得結果容易閱讀;該命令把建立表的ddl顯示出來,於是表結構、型別,外來鍵,備註全部顯示出來了。

我比較喜歡這個命令:輸入簡單,顯示結果全面。

補充一些可能用到的命令:

建表命令:

create table `t_sold_order` (

`id` int(11) not null auto_increment,

`dt` date default null comment '日期',

`hour` tinyint(2) default '0' comment '小時',

`hour_order` int(11) default '0' comment '小時訂單數',

`total_order` int(11) default '0' comment '總的訂單數',

`prediction` int(11) default '0' comment '**訂單數',

primary key (`id`),

unique key `dt_hour` (`dt`,`hour`)

) engine=innodb auto_increment=1 default charset=utf8 comment='實時訂單數'

表操作命令:

複製表結構:create table table1 like table;

複製資料:insert into table1 select * from table

機器授權:

grant select on *.* to 'reader'@'%' identified by '123456' with grant option

flush privileges

查詢資料直接插入

修改表結構

alter table competitor_goods add sku_id bigint(20) unsigned default null comment '商品銷售碼';

mysql key值(pri, uni, mul)的含義:

pri主鍵約束  uni唯一約束  mul可以重複

mysql 查詢表結構

檢視表中字段的結構資訊 可以用來檢視表中字段的注釋等,比如 select table name,column name,column comment from information schema.columns where table schema 表所在的庫 and table name 要檢視...

查詢mysql表結構的語句 查詢表結構的slq語句

1.mysql 和 sqlserver 資料庫 檢視表結構 select from information schema.columns where table name 表名 修改字段長度 alter table 表名 alter column 欄位名 字段型別 字段長度 oracle 資料庫 檢...

SQL Server裡查詢表結構命令

環境 sql server 2008 r2 問題 查詢表結構命令 對mysql和oracle資料庫熟悉的朋友知道用desc就可以查詢一張表的結構,但是在sql server裡執行desc命令會報錯。desc student 關鍵字 desc 附近有語法錯誤。現提供兩條命令查詢表結構 1.sp hel...