我们如何从sql中的过程中找到数据库实例名称

时间:2017-11-03 09:26:48

标签: sql-server tsql

我的问题是:如果我写这样的商店程序:

create procedure test
as
begin
    select * from databasename..Tablename 
end

create procedure test1
as
begin
    select * from databasename..Tablename 
end

然后如何从两个程序上面找到databasename..?我需要一个查询来查找像Databasename..tablename这样使用的过程名称列表。在程序内部

1 个答案:

答案 0 :(得分:0)

试试这个:

create procedure test
as
begin
    select * from databasename..Tablename 
end

GO

create procedure test1
as
begin
    select * from databasename..Tablename 
end

GO




DECLARE @SearchWord NVARCHAR(128) = 'databasename..Tablename'

SELECT ROUTINE_NAME
FROM INFORMATION_SCHEMA.ROUTINES 
WHERE ROUTINE_DEFINITION LIKE '%'+@SearchWord+'%' 
UNION
SELECT OBJECT_NAME(id) 
FROM SYSCOMMENTS 
WHERE [text] LIKE '%'+@SearchWord+'%' 
GROUP BY OBJECT_NAME(id)
UNION 
SELECT OBJECT_NAME(object_id)
FROM sys.sql_modules
WHERE definition LIKE '%'+@SearchWord+'%' 

enter image description here