MySQL 查看錶結構簡單命令(ZZ)

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

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

查詢數據直接插入
insert into t_visual_user_domain(`user_id`,`domain`,`group`) select id,'www.baidu.com' as domain,`group` from t_visual_user;

修改表結構
alter table competitor_goods add sku_id bigint(20) unsigned DEFAULT NULL COMMENT '商品銷售碼';
--------------------- 
作者:Jack小火苗 
來源:CSDN 
原文:https://blog.csdn.net/zhanghao143lina/article/details/69526487 
版權聲明:本文爲博主原創文章,轉載請附上博文鏈接!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章