Sql遍历数据库

时间:2022-10-13 06:29:34

Sql遍历数据库

set nocount on
)
)
)
set @str='ad'
Declare cur_Depart Cursor
For select name,id from syscolumns where id in (Select id From sysobjects Where xtype ='U') and xtype in (select xtype from systypes where name in ( 'varchar', 'nvarchar', 'char', 'nchar','text')) order by id
Open cur_Depart
Fetch From cur_Depart into @CName,@CID

Begin
    )
    )
    Declare @Count int
    set @TName=(Select name From sysobjects Where ID=@CID)
    set @Sql='select @c=Count(*) from '+@TName+' WHERE  PATINDEX(''%'+@Str+'%'','+@CName+')>0'
    exec sp_executesql @Sql,N'@c int output',@Count output
    ) print @TName+'    '+@CName
    Fetch From cur_Depart into @CName,@CID
End
Close cur_Depart
Deallocate cur_Depart