mysqlで列の属性を表示する
以下の4通りのやり方で列の属性を表示することが可能です。
- show columns from テーブル名
- show fields from テーブル名
- describe テーブル名
- desc テーブル名
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
mysql> show columns from kamo_table; +-----------+-----------+------+-----+-------------------+-----------------------------+ | Field | Type | Null | Key | Default | Extra | +-----------+-----------+------+-----+-------------------+-----------------------------+ | id | int(11) | NO | PRI | 0 | | | name | text | NO | | NULL | | | update_ts | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP | +-----------+-----------+------+-----+-------------------+-----------------------------+ 3 rows in set (0.01 sec) mysql> mysql> show fields from kamo_table; +-----------+-----------+------+-----+-------------------+-----------------------------+ | Field | Type | Null | Key | Default | Extra | +-----------+-----------+------+-----+-------------------+-----------------------------+ | id | int(11) | NO | PRI | 0 | | | name | text | NO | | NULL | | | update_ts | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP | +-----------+-----------+------+-----+-------------------+-----------------------------+ 3 rows in set (0.01 sec) mysql> describe kamo_table; +-----------+-----------+------+-----+-------------------+-----------------------------+ | Field | Type | Null | Key | Default | Extra | +-----------+-----------+------+-----+-------------------+-----------------------------+ | id | int(11) | NO | PRI | 0 | | | name | text | NO | | NULL | | | update_ts | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP | +-----------+-----------+------+-----+-------------------+-----------------------------+ 3 rows in set (0.00 sec) mysql> |