MySql查看表的所有字段信息


參考http://hi.baidu.com/maojianlw/item/80e4a82d84b6950f43634a49

mysql和sqlserver中查看當前庫中所有表和字段信息

>>mysql :
1、查看所有表名:
show tables [from db_name];
2、查看字段信息
SHOW FULL COLUMNS FROM db_name.table_name

獲取以下信息
Field :字段名
Type:字段類型
Collation:字符集(mysql 5.0以上有)
Null :是否可以為NULL
Key:索引(PRI,unique,index)
Default:缺省值
Extra:額外(是否 auto_increment)
Privileges:權限
Comment:備注(mysql 5.0以上有)

 1 mysql> create table teacher  # 創建teacher表
 2     -> (
 3     -> Id int (5) auto_increment not null primary key,
 4     -> name char(10) not null, 
 5     -> address varchar(50) default 'No.1 Mid school',
 6     -> year date
 7     -> );
 8 Query OK, 0 rows affected (0.02 sec)
 9 
10 mysql> show tables;
11 +------------------+
12 | Tables_in_school |
13 +------------------+
14 | teacher          |
15 +------------------+
16 1 row in set (0.00 sec)
17 
18 mysql> show full columns from teacher;  # 顯示teacher表的所有字段
19 +---------+-------------+-------------------+------+-----+-----------------+----------------+---------------------------------+---------+
20 | Field   | Type        | Collation         | Null | Key | Default         | Extra          | Privileges                      | Comment |
21 +---------+-------------+-------------------+------+-----+-----------------+----------------+---------------------------------+---------+
22 | Id      | int(5)      | NULL              | NO   | PRI | NULL            | auto_increment | select,insert,update,references |         |
23 | name    | char(10)    | latin1_swedish_ci | NO   |     | NULL            |                | select,insert,update,references |         |
24 | address | varchar(50) | latin1_swedish_ci | YES  |     | No.1 Mid school |                | select,insert,update,references |         |
25 | year    | date        | NULL              | YES  |     | NULL            |                | select,insert,update,references |         |
26 +---------+-------------+-------------------+------+-----+-----------------+----------------+---------------------------------+---------+
27 4 rows in set (0.01 sec)
28 
29 mysql> drop table teacher;  # 刪除teacher表
30 Query OK, 0 rows affected (0.03 sec)
31 
32 mysql> show tables;
33 Empty set (0.00 sec)
34 
35 mysql> 

 


免責聲明!

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



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