Mysql 从 information_schema.columns 选择 count(*)

标签 mysql

我在 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/

相关文章:

php - 计算mysql中的列乘以排序数

mysql - 在 Ruby 中查找相邻的多边形

php - MYSQL - 未能获得独占数据库访问权限

MySQL获取最新的对话消息

php - Laravel 按最多重复项进行 Eloquent 排序

php - ActionScript 看不到文本框的更改

mysql - 查找要插入的记录的主键

php - 在服务器的错误日志文件中获取未定义的 mysqli_connect 函数

Mysql (5.1.41) 存储过程中的动态SQL问题

MySQL 工作台 ALTER USER 语句