Recently when doing a system maintenance for a customer, you need to look at the size of the database table, the related SQL is as follows:
Select the database to be checked and execute the following statement in the top left drop-down box
1. exec sp_spaceused ' table name '-(SQL statistics, may not be allowed after a large number of transactional operations)
2. exec sp_spaceused ' table name ', True--(exact table space size, but may take some time to count)
3. Exec sp_spaceused--(Database size query)
4. Exec sp_msforeachtable "exec sp_spaceused '?" --(all user tablespace tables are small, SQL statistics, and may not be allowed after a large number of transaction operations)
5. Exec sp_msforeachtable "exec sp_spaceused '", true "--(all user tablespace tables are small, big databases are used with caution)
CREATE table #t (name varchar (255), rows bigint, reserved varchar, data varchar, index_size varchar, unused var char (20))
EXEC sp_msforeachtable "INSERT into #t exec sp_spaceused '? '"
SELECT * from #t
drop table #t
Querying the size of a table in a SQL database