1. 程式人生 > >SQL一些常用的查詢語句

SQL一些常用的查詢語句


--欄位查詢表

select a.name, b.name from syscolumns a, sysobjects b
where lower(a.name) = '欄位名'
and   a.id = b.id
and   b.xtype = 'u'


--知道表查儲存過程
select distinct object_name(id) from syscomments where id in
(select object_id from sys.objects where type ='P') and text like'%表名%'




--根據儲存過程內容查詢儲存過程
select b.name 
from syscomments a,sysobjects b 
where a.id=b.id  and b.xtype='p' and a.text like '%需要查詢的內容%'


---知道表查詢關聯的檢視的儲存過程
select distinct object_name(id) from syscomments 
where id in (select id from sysobjects where type  in('V','P')) 
and text like '%表名%'