以下查询列出了数据库中的所有存储过程及其定义。它返回 12 行:
USE [HQ-211-STOCK-DBO]
SELECT OBJECT_NAME (object_id) AS sp_name,
[definition] AS sp_definition
FROM [HQ-211-STOCK-DBO].sys.sql_modules as st
WHERE OBJECTPROPERTY (object_id, 'IsProcedure') = 1
当我更改查询的第一行以使用不同的数据库时:
USE [HQ-193-STOCK-DBO]
SELECT OBJECT_NAME (object_id) AS sp_name,
[definition] AS sp_definition
FROM [HQ-211-STOCK-DBO].sys.sql_modules as st
WHERE OBJECTPROPERTY (object_id, 'IsProcedure') = 1
返回零行。
当我现在更改查询的第 4 行(FROM 行)时:
USE [HQ-193-STOCK-DBO]
SELECT OBJECT_NAME (object_id) AS sp_name,
[definition] AS sp_definition
FROM [HQ-193-STOCK-DBO].sys.sql_modules as st
WHERE OBJECTPROPERTY (object_id, 'IsProcedure') = 1
我得到一排返回。
似乎sys.sql_modules
以数据库名称为前缀并没有像我预期的那样工作。
有人可以指出我做错了什么吗?为什么引用时不能指定数据库名称sys.sql_modules
?