mysql中怎么查询表中的字段个数
答案:1 悬赏:80 手机版
解决时间 2021-11-19 06:05
- 提问者网友:心牵心
- 2021-11-18 22:52
mysql中怎么查询表中的字段个数
最佳答案
- 五星知识达人网友:上分大魔王
- 2021-11-19 00:22
方法一,在你的程序中直接
desc tablename
然后总行数就是你的字段数。
mysql> desc ysks;
+-------+---------------+-----
| Field | Type | Null
+-------+---------------+-----
| 单号 | int(11) | YES
| 金额 | decimal(10,2) | YES
| 已收 | decimal(10,2) | YES
| 日期 | bigint(20) | YES
| 名称 | varchar(10) | YES
| 余额 | decimal(10,2) | YES
| 备注 | varchar(10) | YES
| 品名 | varchar(10) | YES
+-------+---------------+-----
8 rows in set (0.06 sec)
mysql> select FOUND_ROWS();
+--------------+
| FOUND_ROWS() |
+--------------+
| 8 |
+--------------+
1 row in set (0.06 sec)
mysql>
方法二,通过系统表information_schema.`COLUMNS` ( mysql5以上版本支持)
mysql> select count(*) from information_schema.`COLUMNS`
-> where TABLE_SCHEMA='csdn'
-> and TABLE_NAME='ysks';
+----------+
| count(*) |
+----------+
| 8 |
+----------+
1 row in set (0.06 sec)
mysql>
desc tablename
然后总行数就是你的字段数。
mysql> desc ysks;
+-------+---------------+-----
| Field | Type | Null
+-------+---------------+-----
| 单号 | int(11) | YES
| 金额 | decimal(10,2) | YES
| 已收 | decimal(10,2) | YES
| 日期 | bigint(20) | YES
| 名称 | varchar(10) | YES
| 余额 | decimal(10,2) | YES
| 备注 | varchar(10) | YES
| 品名 | varchar(10) | YES
+-------+---------------+-----
8 rows in set (0.06 sec)
mysql> select FOUND_ROWS();
+--------------+
| FOUND_ROWS() |
+--------------+
| 8 |
+--------------+
1 row in set (0.06 sec)
mysql>
方法二,通过系统表information_schema.`COLUMNS` ( mysql5以上版本支持)
mysql> select count(*) from information_schema.`COLUMNS`
-> where TABLE_SCHEMA='csdn'
-> and TABLE_NAME='ysks';
+----------+
| count(*) |
+----------+
| 8 |
+----------+
1 row in set (0.06 sec)
mysql>
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯