Mysql从information_schema.columns中选择count(*)

时间:2014-04-18 15:30:17

标签: 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'。我不知道为什么,它应该是3

1 个答案:

答案 0 :(得分:2)

您需要按架构限制查询:

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';