使用sp_MSForEachTable這個系統存儲過程。ide
建立一張臨時表,它有2個字段,[Table_Name]和[Total_Records]。spa
而後使用sp_MSForEachTable來處理,把結果插入上面建立的臨時表中。若是Total_Records爲0的,說明此表沒有任何記錄。code
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