Mysql从information_schema.columns中选择count(*)
我在mysql中有一个表命名用户:Mysql从information_schema.columns中选择count(*),mysql,Mysql,我在mysql中有一个表命名用户: 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
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';
知道为什么吗?执行此查询:
select*from information_schema.columns,其中table_name='users'代码>在另一个模式中可能有另一个表“users”?尝试在WHERE子句中包含模式。感谢Grijesh Chauhan和abl,在另一个基础中还有另一个表用户