如何在SQL server查找被引用的字段
在进行数据库开发中,难免有很多表,视图或者存储过程用到很多字段,有时候一个更改搞不好就有一大堆问题出现,因此,在更改之前查询一下哪些地方引用了字段就很有必要了。
查找在表中引用
select sysobjects.name from syscolumns inner join sysobjects on syscolumns.id =
sysobjects.id and sysobjects.xtype = 'u' where syscolumns.name = '字段名'
查找在视图中引用
select distinct object_name(id) from syscomments where id in
(select id from sysobjects where type ='V') and text like '%字段名%'
查找在存储过程中引用
select distinct object_name(id) from syscomments where id in
(select id from sysobjects where type ='P') and text like '%字段名%'