MySQL查詢表與表字段的信息


環境:

Mysql數據庫
庫名:db_name
表名: table_name1 table_name2

查詢一個里面所有表的信息:

use information_scheam;
select * from tables where table_schema = "db_name";

查詢單個表的信息:

use information_scheam;
select * from tables where table_schema = "db_name" and table_name = "table_name1";

查詢一張表的所有字段信息:

use db_name;
show full columns from table_name1;
show full columns from table_name2;

一些基礎:

# 創建表
create table book( id int(
11) primary key, title varchar(50) comment '書名', author varchar(32) comment '作者', price int(8) comment '價格' );

# 修改表備注信息
alter table student comment '書籍表';

# 修改表字段長度
alter table book modify column author varchar(50);

# 修改表字段備注信息
alter table book modify column author varchar(50) comment '作者姓名';

# 給表增加新字段
alter table book add publisher varchar(100) comment '出版社';

# 在指定列后面增加新字段
alter table book add publisher varchar(200) comment '出版社' after author;

# 刪除表字段
alter table book drop column price;

# 查看表備注信息和表字段備注信息請看上文。


 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM