2

如果我提供列名作为存储过程的输入,我应该从所有数据库中使用该列获取过程和表名列表吗?

4

1 回答 1

2

对于 sql-server 2005+,您可以使用:

create procedure sp1
    @columnName varchar(30)
as
    select s1.name,'table' type
    from sys.objects s1 join sys.columns s2 on s1.object_id = s2.object_id
    where s2.name = @columnName  and s1.type = 'U'

    union

    select s1.name,'procedure' type
    from sys.procedures s1 join sys.sql_modules s2 on s1.object_id = s2.object_id
    and s2.definition like '%'+@columnName+'%'
于 2012-08-13T18:07:31.693 回答