How to know which tables in the database have no records


Use SP? Msforeachtable, the system stored procedure.

Create a temporary table with 2 fields, [table name] and [total records].

Then use sp ﹣ msforeachtable to process and insert the result into the temporary table created above. If the total “records is 0, there are no records in this table.


    DROP TABLE #Temp_T

    CREATE TABLE #Temp_T   
        [Table_Name] NVARCHAR(128), 
        [Total_Records] INT  
    EXEC sp_MSForEachTable @command1 = 'INSERT INTO #Temp_T([Table_Name], [Total_Records]) SELECT ''?'', COUNT(*) FROM ?'  ;
    SELECT [Table_Name],[Total_Records] FROM #Temp_T ORDER BY [Total_Records] DESC

Source Code


Recommended Today

Construction and experiment of Kafka, ZK cluster development or deployment environment

This article is original, reprint and indicate the source, welcome to pay attention to wechat appletXiaobai AI blogWeChat official accountXiaobai AIOr website Or my CSDN [TOC] 1 foreword Other features of Kafka will not be discussed here. This article is mainly about the construction of cluster development environment. For details of Kafka’s relevant […]