Summry
본 문서에서는 테이블을 만들고 나서 칼럼의 타입을 확인하고자 할 때 사용할 방법들을 정리한다.
send me email if you have any questions.
1. SHOW COLUMNS
전체 field 보기
mysql> SHOW COLUMNS FROM `user_info`;
+--------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+----------------+
| idx | int(11) | NO | PRI | NULL | auto_increment |
| device_token | varchar(255) | YES | UNI | NULL | |
+--------------+--------------+------+-----+---------+----------------+
2 rows in set (0.004 sec)
특정 field만 보기
mysql> SHOW COLUMNS FROM `user_info` LIKE 'idx';
+-------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+----------------+
| idx | int(11) | NO | PRI | NULL | auto_increment |
+-------+---------+------+-----+---------+----------------+
1 row in set (0.004 sec)
2. desc
mysql> desc user_info;
+--------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+----------------+
| idx | int(11) | NO | PRI | NULL | auto_increment |
| device_token | varchar(255) | YES | UNI | NULL | |
+--------------+--------------+------+-----+---------+----------------+
2 rows in set (0.006 sec)
3. information_schema
전체 field 보기
mysql> SELECT DATA_TYPE FROM information_schema.COLUMNS WHERE TABLE_NAME='user_info';
+-----------+
| DATA_TYPE |
+-----------+
| int |
| varchar |
+-----------+
2 rows in set (0.005 sec)
특정 field만 보기
mysql> SELECT DATA_TYPE FROM information_schema.COLUMNS WHERE TABLE_NAME='user_info' AND COLUMN_NAME='device_token';
+-----------+
| DATA_TYPE |
+-----------+
| varchar |
+-----------+
1 row in set (0.005 sec)
전체 field 보기
mysql> SELECT COLUMN_TYPE FROM information_schema.COLUMNS WHERE TABLE_NAME='user_info';
+--------------+
| COLUMN_TYPE |
+--------------+
| int(11) |
| varchar(255) |
+--------------+
2 rows in set (0.005 sec)
특정 field만 보기
mysql> SELECT COLUMN_TYPE FROM information_schema.COLUMNS WHERE TABLE_NAME='user_info' AND COLUMN_NAME='device_token';
+--------------+
| COLUMN_TYPE |
+--------------+
| varchar(255) |
+--------------+
1 row in set (0.005 sec)
Reference
PREVIOUSMySql 화면지우기(clear)