查找一个数据库(MSSQL)任意表中内容【网管必须了解的数据操作知识】
有时在工作时,需要在数据中修改一个数据或者参数,但又不知道具体在哪个数据库表中,而每一个表中去打开去查找的话,就太麻烦了今天小编教小童鞋摆脱这痛苦。
话不多说,直接来数据库语句:
declare @Str nvarchar(max), @tableName varchar(50), @colName varchar(50), @rowCount int
select a.name tableName, b.name Colname, 0 as IsFound into #t1
from sysobjects a join syscolumns b on a.id=b.id join systypes c on b.xtype=c.xtype
where a.='U' and c.name in ('varchar', 'nvarchar', 'char', 'nchar') --这里是设置字段的类型,以缩小范围
declare _c1 cursor for select Colname, tableName from #t1
open _c1
**** Hidden Message *****
end
close _c1
deallocate _c1
select * from #t1 where IsFound=1
drop table #t1
页:
[1]