获取某个视图、触发器、函数、过程的所属关联表

declare @name varchar(800),@sqls nvarchar(500)


DECLARE curObject1 CURSOR FOR               --声明游标
    select [name]
        from  sysobjects where xtype='U' and name<>'dtproperties' order by [name]
OPEN  curObject1                            --打开游标
FETCH NEXT FROM curObject1 INTO @name  --把游标读取的值赋给变量
WHILE(@@FETCH_STATUS=0 )   --判断是否还有下一行数据
 begin

  set @sqls = 'select ''' + @name+''' as dn,a.name from sysobjects a, syscomments b where a.id = b.id and b.text like ''%'  +@name+  '%'''
  exec(@sqls)
  FETCH NEXT FROM curObject1 INTO @name   --相当于recordset.Movenext
 end

 

close curObject1             --关闭游标
deallocate curObject1        --释放游标

你可能感兴趣的:(触发器)