éä½ äºï¼ä¸è°¢
declare @cloumns varchar(40)
declare @tablename varchar(40)
declare @str varchar(40)
declare @counts int
declare @sql nvarchar(2000)
declare MyCursor Cursor For
Select a.name as Columns, b.name as TableName from syscolumns a,sysobjects b,systypes c
where a.id = b.id
and b.type = 'U'
and a.xtype=c.xtype
and c.name like '%char%'
set @str='å¼ ä¸' --è¿ä¸ªå¼ ä¸çå°æ¹è¾å
¥è¦æ¥æ¾çå符串
Open MyCursor
Fetch next From MyCursor Into @cloumns,@tablename
While(@@Fetch_Status = 0)
Begin
set @sql='select @tmp_counts=count(*) from ' +@tablename+ ' where ' +@cloumns+' = ''' +@str+ ''''
execute sp_executesql @sql,N'@tmp_counts int out',@counts out
if @counts>0
begin
print '表å为:'+@tablename+',å段å为'+@cloumns
end
Fetch next From MyCursor Into @cloumns,@tablename
End
Close MyCursor
Deallocate MyCursor
å¦æ¬é¢ï¼æ¯æ¥æ¾åºä¸ï¼å
å«âå¼ ä¸âçæ°æ®ç表ã
ç»æå¦å¾ï¼
ç¶åä½ å°±è½æ¾å°æ°æ®äº
select * from users where uname='å¼ ä¸'