This article introduces the number of all data records in the SQL statistical table. Here we can count the records of all tables in the database. If you need them, refer to the following.
This article introduces the number of all data records in the SQL statistical table. Here we can count the records of all tables in the database. If you need them, refer to the following.
Recently, the company found that table data has been removed, and some data tables have records of 0. Therefore, we want to find out which data tables in the database have records of 0 to narrow the analysis scope, the following SQL Statement can be used:
| The Code is as follows: |
|
|
Create table # tmptb (tbname sysname, tbrows int
, TbREserved varchar (10), tbData varchar (10)
, TbIndexSize varchar (10), tbUnUsed varchar (10 ))
Insert into # tmptb exec sp_MSForEachTable 'exec sp_spaceused ''? '''
SELECT * from # tmptb -- list all tables
SELECT tbrows, tbname FROM # tmptb WHERE tbrows = 0 -- list tables whose record data is 0
Order by tbname
Drop table # tmptb |
Where
Tbname table name
Tbrows records
TbREserved reserved space
TbData Space
TbIndexSize index space
TbUnUsed unused space