mysql查詢表字所有欄位的方法:使用“SHOW FROM”語句來配合FULL關鍵字來查詢,語法“SHOW FULL COLUMNS FROM table_name”,可以顯示指定資料表的所有欄位資訊。
mysql查詢表字所有欄位
1、檢視所有表名:
show tables [from db_name];
2、查看欄位資訊
SHOW FULL COLUMNS FROM table_name
取得下列資訊
Field :欄位名稱
Type:欄位類型
Collation:字元集(mysql 5.0以上有)
Null :是否可以為NULL
Key:索引(PRI,unique,index)
Default:預設值
Extra:額外(是否auto_increment)
Privileges:權限
# Comment:備註(mysql 5.0以上有)
mysql> create table teacher # 创建teacher表 -> ( -> Id int (5) auto_increment not null primary key, -> name char(10) not null, -> address varchar(50) default 'No.1 Mid school', -> year date -> ); Query OK, 0 rows affected (0.02 sec) mysql> show tables; +------------------+ | Tables_in_school | +------------------+ | teacher | +------------------+ 1 row in set (0.00 sec) mysql> show full columns from teacher; # 显示teacher表的所有字段 +---------+-------------+-------------------+------+-----+-----------------+----------------+---------------------------------+---------+ | Field | Type | Collation | Null | Key | Default | Extra | Privileges | Comment | +---------+-------------+-------------------+------+-----+-----------------+----------------+---------------------------------+---------+ | Id | int(5) | NULL | NO | PRI | NULL | auto_increment | select,insert,update,references | | | name | char(10) | latin1_swedish_ci | NO | | NULL | | select,insert,update,references | | | address | varchar(50) | latin1_swedish_ci | YES | | No.1 Mid school | | select,insert,update,references | | | year | date | NULL | YES | | NULL | | select,insert,update,references | | +---------+-------------+-------------------+------+-----+-----------------+----------------+---------------------------------+---------+ 4 rows in set (0.01 sec) mysql> drop table teacher; # 删除teacher表 Query OK, 0 rows affected (0.03 sec) mysql> show tables; Empty set (0.00 sec) mysql>
推薦教學:mysql影片教學
#以上是mysql如何查詢表字所有欄位?的詳細內容。更多資訊請關注PHP中文網其他相關文章!