我在 mysql 中有一个名为 users 的表:
Create table users(
user_id in not null primary key AUTO_INCREMENT,
username varchar(20) not null unique,
password varchar(20) not null
);
当我执行时
select count(*) from information_schema.columns where table_name = 'users';
它返回我'12'
。不知道为什么,应该是3
。
最佳答案
您需要通过模式限制查询:
select count(*)
from information_schema.columns
where table_schema = 'your_schema'
and table_name = 'users';
或者,如果您已经在相关架构中,则可以使用它作为快捷方式:
select count(*)
from information_schema.columns
where table_schema = database()
and table_name = 'users';
关于Mysql 从 information_schema.columns 选择 count(*),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23157247/