如何查询出数据库中表不为空的表名?

accp_cc 2009-01-02 04:53:17
如何查询出数据库中表不为空的表名?
...全文
384 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
worlddba 2009-01-04
  • 打赏
  • 举报
回复
牛X
水族杰纶 2009-01-03
  • 打赏
  • 举报
回复
create   table   #tb(表名   sysname,记录数   int   ,保留空间   varchar(10),使用空间   varchar(10),索引使用空间   varchar(10),未用空间   varchar(10))       
insert into #tb exec sp_MSForEachTable 'EXEC sp_spaceused ''?'''
select 表名 from #tb where 记录数 =0
go
drop table #tb
hack1238 2009-01-03
  • 打赏
  • 举报
回复
牛啊
accp_cc 2009-01-02
  • 打赏
  • 举报
回复
不为空的表名,表名!!!
第2楼的对了,谢谢!
dawugui 2009-01-02
  • 打赏
  • 举报
回复
[Quote=引用楼主 accp_cc 的帖子:]
如何查询出数据库中表不为空的表名?
[/Quote]
哦,是查不为空的表啊,把num = 0 改为 num <> 0 ,刚才看错了,不好意思.
百年树人 2009-01-02
  • 打赏
  • 举报
回复
1 木娄 弓虽

楼主要找不为空的表,把where num = 0 改为 where num <> 0 即可
dawugui 2009-01-02
  • 打赏
  • 举报
回复
--因sql server 2000自带pubs库中没有记录数为0的表,以下为查个表的记录数
declare @sql varchar(8000)
set @sql='select * from ('
select @sql=@sql+' select name = ''' + name + ''' , count(*) as num from ['+name+'] union all ' from sysobjects where xtype='u'
set @sql = left(@sql,len(@sql) - 10) + ')a'
exec(@sql)

/*
name num
----------- -----------
titleauthor 25
stores 6
sales 21
roysched 86
discounts 3
jobs 14
pub_info 8
employee 43
authors 23
publishers 8
titles 18
*/
dawugui 2009-01-02
  • 打赏
  • 举报
回复
declare @sql varchar(8000)
set @sql='select * from ('
select @sql=@sql+' select name = ''' + name + ''' , count(*) as num from ['+name+'] union all ' from sysobjects where xtype='u'
set @sql = left(@sql,len(@sql) - 10) + ')a where num = 0'
exec(@sql)

/*
name num
----------- -----------
*/

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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