您好,登錄后才能下訂單哦!
小編給大家分享一下MySQL中如何查看表結(jié)構(gòu),相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
一、簡(jiǎn)單描述表結(jié)構(gòu),字段類(lèi)型
desc tabl_name;
顯示表結(jié)構(gòu),字段類(lèi)型,主鍵,是否為空等屬性,但不顯示外鍵。
例如:desc table_name
二、查詢表中列的注釋信息
select * from information_schema.columns
where table_schema = 'db' #表所在數(shù)據(jù)庫(kù)
and table_name = 'tablename' ; #你要查的表
可以自動(dòng)選擇你需要信息
三、只查詢列名和注釋
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è)命令雖然顯示起來(lái)不是太容易看, 這個(gè)不是問(wèn)題可以用\G來(lái)結(jié)尾,使得結(jié)果容易閱讀;該命令把創(chuàng)建表的DDL顯示出來(lái),于是表結(jié)構(gòu)、類(lèi)型,外鍵,備注全部顯示出來(lái)了。
我比較喜歡這個(gè)命令:輸入簡(jiǎn)單,顯示結(jié)果全面。
補(bǔ)充一些可能用到的命令:
建表命令:
CREATE TABLE `t_sold_order` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`dt` date DEFAULT NULL COMMENT '日期',
`hour` tinyint(2) DEFAULT '0' COMMENT '小時(shí)',
`hour_order` int(11) DEFAULT '0' COMMENT '小時(shí)訂單數(shù)',
`total_order` int(11) DEFAULT '0' COMMENT '總的訂單數(shù)',
`prediction` int(11) DEFAULT '0' COMMENT '預(yù)測(cè)訂單數(shù)',
PRIMARY KEY (`id`),
UNIQUE KEY `dt_hour` (`dt`,`hour`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='實(shí)時(shí)訂單數(shù)'
表操作命令:
復(fù)制表結(jié)構(gòu):create table table1 like table;
復(fù)制數(shù)據(jù):insert into table1 select * from table
機(jī)器授權(quán):
grant select on *.* to 'reader'@'%' identified by '123456' WITH GRANT OPTION
flush privileges
查詢數(shù)據(jù)直接插入:
insert into t_visual_user_domain(`user_id`,`domain`,`group`) select id,'www.baidu.com' as domain,`group` from t_visual_user;
修改表結(jié)構(gòu):
alter table competitor_goods add sku_id bigint(20) unsigned DEFAULT NULL COMMENT '商品銷(xiāo)售碼'。
以上是“MySQL中如何查看表結(jié)構(gòu)”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。