Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server information_schema.columns向我的SQL Server代理返回0行_Sql Server_Sql Server Agent_Information Schema - Fatal编程技术网

Sql server information_schema.columns向我的SQL Server代理返回0行

Sql server information_schema.columns向我的SQL Server代理返回0行,sql-server,sql-server-agent,information-schema,Sql Server,Sql Server Agent,Information Schema,我只是陷入了这个问题,不幸的是,我找不到任何解决办法,即使在谷歌搜索的时候 我正在SQL Server 2005数据库上运行以下查询: select @TableCount = count(distinct table_name) from information_schema.columns 我在不同的数据库中得到了@TableCount的不同结果,例如: 59, 22, 等等 但是,当我让我的SQL Server代理在相同的数据库上运行相同的查询时,其结果总是为0。也就是说,没有例外,

我只是陷入了这个问题,不幸的是,我找不到任何解决办法,即使在谷歌搜索的时候

我正在SQL Server 2005数据库上运行以下查询:

select @TableCount = count(distinct table_name) 
from information_schema.columns
我在不同的数据库中得到了@TableCount的不同结果,例如:

59,
22,
等等

但是,当我让我的SQL Server代理在相同的数据库上运行相同的查询时,其结果总是为0。也就是说,没有例外,没有错误消息表明他的访问权限有问题——结果只是0

如果您有任何想法,请提供帮助:

我的SQL Server代理可能有什么问题? 为什么不管问题是什么,我都没有收到任何错误消息?
提前多谢您的建议

您将哪个数据库设置为默认数据库


模型为我返回0。

我确信十年后对@Gustin没有帮助,但其他人可能会遇到这种情况。问题可能是用户表上的权限。 参考:关于Transact-SQL列的Microsoft文档 为当前数据库中当前用户可以访问的每列返回一行。 我通过创建一个新表进行了验证,确认用户从中获得了0行

    SELECT *
    FROM INFORMATION_SCHEMA.COLUMNS
    WHERE TABLE_NAME = <userTableName>

将SELECT权限授予用户,则行由同一查询返回。

如果您发布代码或XML,请在文本编辑器中突出显示这些行,然后单击编辑器工具栏上的“代码”按钮101 010,以精确格式化并语法突出显示它!实际上,您可以在任何数据库中运行我上面提到的脚本,即使是在master或msdb中,如果您愿意的话,您也可以得到一个正数,即该数据库中没有系统表和视图的表和视图的总数。模型是我所知道的唯一的例外-'因为除了系统之外,这里既没有表也没有视图。