如何列出数据库中所有表内容在一行及以上的表中的内容?

安琪有纪 2008-03-04 10:35:15
如题,也就是要把所有非空的表中的内容列出来
...全文
94 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
wukele 2008-03-30
  • 打赏
  • 举报
回复
又学到一个存储过程
chuifengde 2008-03-04
  • 打赏
  • 举报
回复
sp_msforeachtable 'if (select top 1 rows from sysindexes where id=object_id(''?'') and status=0)>0 select ''?'' 表名, * from ?'
liangCK 2008-03-04
  • 打赏
  • 举报
回复
上面纯属手写,可能存在手误.
青锋-SS 2008-03-04
  • 打赏
  • 举报
回复
从系统表sysobjects里面检索表名,然后再用动态语句检索
liangCK 2008-03-04
  • 打赏
  • 举报
回复
decuare cur cursor for 
select name from sysobjects where xtype='U'
declare @tbname varchar(128)
declare @cnt int
declare @sql nvarchar(400)
open cur
fetch next from cur into @tbname
while @@fetch_status=0
begin
set @sql=N'select @cnt=count(*) from ['+@bname+N']'
exec sp_executesql @sql,'@cnt int output',@cnt output
if @cnt>0
exec ('select * from ['+@tbname+']')
fetch next from cur into @tbname
end
close cur
deallocate cur
chuifengde 2008-03-04
  • 打赏
  • 举报
回复
那就
sp_msforeachtable 'if exists(select top 1 1 from ?) select ''?'' 表名, * from ?'
安琪有纪 2008-03-04
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 chuifengde 的回复:]
SQL codesp_msforeachtable 'if (select top 1 rows from sysindexes where id=object_id(''?'') and status=0)>0 select ''?'' 表名, * from ?'
[/Quote]

这个选出来的不全,却又不知道差在哪儿
安琪有纪 2008-03-04
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 liangCK 的回复:]
上面纯属手写,可能存在手误.
[/Quote]


过程需要参数 '@parameters' 为 'ntext/nchar/nvarchar' 类型。

这个需要2005 不? 2000能执行?

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧