如何在MySQL中查找列名?
为此,您可以使用SHOW COLUMNS或INFORMATION_SCHEMA.COLUMN。
让我们首先创建一个表-
mysql> create table DemoTable603(
ClientId int NOT NULL AUTO_INCREMENT,
ClientName varchar(100),
ClientAge int,
ClientAddress varchar(100),
ClientCountryName varchar(100),
ClientEducationDetails varchar(200),
PRIMARY KEY(ClientId)
);
案例1 - 使用SHOW命令
这是查找MySQL中列名称的查询-
mysql> SHOW COLUMNS FROM DemoTable603;
这将产生以下输出-
+------------------------+--------------+------+-----+---------+----------------+| Field | Type | Null | Key | Default | Extra |
+------------------------+--------------+------+-----+---------+----------------+
| ClientId | int(11) | NO | PRI | NULL | auto_increment |
| ClientName | varchar(100) | YES | | NULL | |
| ClientAge | int(11) | YES | | NULL | |
| ClientAddress | varchar(100) | YES | | NULL | |
| ClientCountryName | varchar(100) | YES | | NULL | |
| ClientEducationDetails | varchar(200) | YES | | NULL | |
+------------------------+--------------+------+-----+---------+----------------+
6 rows in set (0.00 sec)
案例2-使用information_schema.column-
mysql> select column_name from information_schema.columns where table_schema='web' and table_name='DemoTable603';
这将产生以下输出-
+------------------------+| COLUMN_NAME |
+------------------------+
| ClientAddress |
| ClientAge |
| ClientCountryName |
| ClientEducationDetails |
| ClientId |
| ClientName |
+------------------------+
6 rows in set (0.00 sec)
以上是 如何在MySQL中查找列名? 的全部内容, 来源链接: utcz.com/z/323925.html