使用sp_msforeachtable这个系统存储过程。
创建一张临时表,它有2个字段,[table_name]和[total_records]。
然后使用sp_msforeachtable来处理,把结果插入上面创建的临时表中。如果total_records为0的,说明此表没有任何记录。
drop table #temp_t go create table #temp_t ( [table_name] nvarchar(128), [total_records] int ) go exec sp_msforeachtable @command1 = 'insert into #temp_t([table_name], [total_records]) select ''?'', count(*) from ?' ; go select [table_name],[total_records] from #temp_t order by [total_records] desc
需要了解更多数据库技术:如何知道数据库中哪些表没有记录,都可以关注数据库技术分享栏目—计算机技术网(www.ctvol.com)!
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/dtteaching/628430.html