create proc full_search(@string varchar(50))
as begin
declare @tbname varchar(50)
declare tbroy cursor for select name from sysobjects
where xtype= 'u ' --第乙個游標遍歷所有的表
open tbroy
fetch next from tbroy into @tbname
while @@fetch_status=0
begin
declare @colname varchar(50)
declare colroy cursor for select name from syscolumns
where id=object_id(@tbname) and xtype in (
select xtype from systypes
where name in ( 'varchar ', 'nvarchar ', 'char ', 'nchar ') --資料型別為字元型的字段
) --第二個游標是第乙個游標的巢狀游標,遍歷某個表的所有字段
open colroy
fetch next from colroy into @colname
while @@fetch_status=0
begin
declare @sql nvarchar(1000),@j int
select @sql= 'select @i=count(1) from ' +@tbname + ' where '+ @colname+ ' like '+ '''%'+@string+ '%'''
exec sp_executesql @sql,n'@i int output',@i=@j output --輸出滿足條件表的記錄數
if @j> 0
begin
select 包含字串的表名=@tbname
--exec( 'select distinct '+@colname+' from ' +@tbname + ' where '+ @colname+ ' like '+ '''%'+@string+ '%''')
endfetch next from colroy into @colname
end
close colroy
deallocate colroy
fetch next from tbroy into @tbname
end
close tbroy
deallocate tbroy
end
go
SQL技巧 查詢某個表關聯的所有儲存過程
關鍵字 sql技巧 在開發過程中,可能需要更改某乙個表的資料結構,或者更新資料。但你又不太清楚會造成什麼影響,遲遲不敢下手進行調整。筆者 快樂it 最近在做erp k3與oa藍凌介面時就遇到了這個問題,那是否有辦法知道我們所修改的table有哪些儲存過程引用了,哪些檢視關聯了即將要修改的表呢。答案是...
sql server 查詢某個表的所有觸發器名稱
查出所有用到某個表的sql select from sysobjects where xtype tr select from sysobjects where xtype tr and parent obj object id 表名 xtype char 2 物件型別。可以是下列物件型別中的一種 ...
sql server 查詢某個表的所有觸發器名稱
查出所有用到某個表的sql select from sysobjects where xtype tr select from sysobjects where xtype tr and parent obj object id 表名 xtype char 2 物件型別。可以是下列物件型別中的一種 ...