首页 > 开发 > 综合 > 正文

Sql遍历数据库

2024-07-21 02:46:48
字体:
来源:转载
供稿:网友
Sql遍历数据库

Sql遍历数据库

set nocount onDeclare @Str varchar(50)Declare @CName varchar(50)Declare @CID varchar(20)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 idOpen cur_DepartFetch From cur_Depart into @CName,@CIDWhile @@Fetch_Status=0Begin    Declare @Sql nvarchar(500)    Declare @TName nvarchar(500)    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    if (@Count>0) PRint @TName+'    '+@CName    Fetch From cur_Depart into @CName,@CIDEndClose cur_DepartDeallocate cur_Depart


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表