查询 数据库所有用户表 的记录,对分析数据库表的结构很有用,很方便,贴出来,备用!
2009-05-11 17:45
531 查看
随手写的SQl脚本,
查询 数据库所有用户表 的记录,对分析数据库表的结构很有用,很方便,贴出来,备用!
=''' +@tname+''',* from ' +@tname
exec(@sqlstr)
fetch next from @cr into @tname
set @i = @i+1
print @tname
print @i
end
close @cr
DEALLOCATE @cr
查询 数据库所有用户表 的记录,对分析数据库表的结构很有用,很方便,贴出来,备用!
declare @cr cursor declare @tname varchar(100) declare @sqlstr varchar(8000) declare @i int set @cr = cursor for select name from sysobjects where type='u' --and [name] like '%%' open @cr fetch next from @cr into @tname set @i = 0 while @@fetch_status = 0 begin set @sqlstr = 'select top 10