0

我有表:

SHOW COLUMNS FROM `darbuotojai`;
+--------------+--------------+------+-----+---------+----------------+
| Field        | Type         | Null | Key | Default | Extra          |
+--------------+--------------+------+-----+---------+----------------+
| id           | int(10)      | NO   | PRI | NULL    | auto_increment |
| vardas       | char(20)     | YES  |     | NULL    |                |
| pavarde      | char(30)     | YES  |     | NULL    |                |
| email        | char(100)    | YES  |     | NULL    |                |
| pareigos     | char(50)     | YES  |     | NULL    |                |
| ilg_tel_nr   | decimal(8,0) | NO   | PRI | 0       |                |
| trump_tel_nr | decimal(3,0) | NO   | PRI | 0       |                |
| inv_nr       | char(10)     | YES  |     | NULL    |                |
+--------------+--------------+------+-----+---------+----------------+

如何使用 sql 命令计算表中的列?以及如何识别它们?

4

3 回答 3

1
SELECT COUNT(*)
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_schema = 'database_name'
  AND table_name = 'tbl_name'
于 2013-05-23T05:56:56.317 回答
1
SELECT count(*)
FROM information_schema.columns
WHERE table_name = 'darbuotojai'
于 2013-05-23T05:57:11.493 回答
1
SELECT count(*) FROM information_schema.`COLUMNS` C
WHERE table_name = 'your_table_name'
AND TABLE_SCHEMA = "your_db_name"

仅当表名存在于多个数据库中时才需要 TABLE_SCHEMA

于 2013-05-23T05:57:31.377 回答