SQL Server has a system stored procedure called sp_spaceused
that enables you to check the size of a table in a database.
You can use it to check the number of rows, disk space reserved, and disk space used by a table, indexed view, or Service Broker queue in the current database, or the disk space reserved and used by the whole database.
Example
Here’s an example to demonstrate.
EXEC sp_spaceused @objname = 'Application.Cities';
You can also omit the @objname
part if you prefer.
EXEC sp_spaceused 'Application.Cities';
Either way, they both provide the same result.
Result:
+--------+----------------------+------------+---------+--------------+----------+ | name | rows | reserved | data | index_size | unused | |--------+----------------------+------------+---------+--------------+----------| | Cities | 37940 | 4880 KB | 3960 KB | 896 KB | 24 KB | +--------+----------------------+------------+---------+--------------+----------+
To save you from having to scroll sideways, here’s that result again, but this time using vertical output:
name | Cities rows | 37940 reserved | 4880 KB data | 3960 KB index_size | 896 KB unused | 24 KB
If you omit all arguments, sp_spaceused
will return info for the whole database. This is just one of many ways to return the size of a database in SQL Server.