SQL 查询数据库是否存在该表该字段该内容

 1 查看数据库是否存在该表
 2 方法1
 3 select distinct object_name(id) from syscomments where id in
 4 (select id from sysobjects where type ='P') and text like '%Bak%'
 5 
 6 方法2
 7 GO  
 8 SELECT DISTINCT obj.Name 存储过程名, sc.TEXT 存储过程内容  
 9 FROM syscomments sc  
10 INNER JOIN sysobjects obj ON sc.Id = obj.ID  
11 WHERE sc.TEXT LIKE '%' + 'SeatType' + '%'  
12 AND TYPE = 'P'  
13 GO  
14 
15 查询所有数据库有用到该字段的数据库
16 
17 EXEC master..SearchProcOrFuncProc @srh = N'mt_community_seat_tbl', @srh1 = N'SeatType', @dbs = N'', @orders = N'dbname, name';
18 查看存储过程的内容
19 select text from syscomments where id=object_id('存储过程名')
20 --- 或者
21 sp_helptext  存储过程名
22 
23 查看包含字符串内容的存储过程
24 select   b.name   ,a.text   from   syscomments   a,sysobjects   b 
25 where 
26 charindex('字符串内容',a.text)>0    and 
27 object_id(b.name)=a.id   and   b.xtype   in('P','TR')

 

posted @ 2022-03-15 14:19  SDdemon  阅读(312)  评论(0编辑  收藏  举报