获取MySQL表中的字段数?
要显示MySQL中的字段数,请使用COUNT(*)。以下是语法-
select COUNT(*) AS anyAliasNamefrom INFORMATION_SCHEMA.COLUMNS
where table_name = yourTableName AND
TABLE_SCHEMA = yourDatabaseName;
让我们首先创建一个表-
mysql> create table DemoTable794 (ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY,
ClientName varchar(100),
ClientAge int,
ClientCountryName varchar(100)
);
以下是获取MySQL中字段数的查询-
mysql> select COUNT(*) AS TOTAL_NUMBER_OF_COLUMNSfrom INFORMATION_SCHEMA.COLUMNS
where table_name = 'DemoTable794' AND
TABLE_SCHEMA = 'web';
这将产生以下输出-
+-------------------------+| TOTAL_NUMBER_OF_COLUMNS |
+-------------------------+
| 4 |
+-------------------------+
1 row in set (0.00 sec)
以上是 获取MySQL表中的字段数? 的全部内容, 来源链接: utcz.com/z/326854.html