I am attempting to use the stored procedure sp_spaceused to retrieve the amount of space used by the tables in a database. IMPORTANT: I want to be able to make a query that returns this data, and cannot create a table.
The default use of this stored procedure outputs a table that contains the name of the database, the database size, and the unallocated space. By using the @objname parameter, you can choose to only return the space used of one table in the database and will return the name of the table, the number of rows the table has, the space reserved, the data, the index size, and the unused space.
What I want, is to take the values returned when using the @objname parameter for every table in the database, and combine them into a single output table. Say a database had 1000 tables in it. The final result should be, an output table with 1000 rows that has columns for the name of each table, the number of rows each table has, the space reserved, the data, the index size, and the unused space. (the outputs of the sp_spaceused stored procedure with the @objname parameter defined) If there is some other way to achieve what I want without sp_spaceused, I am open to suggestions.
Say this is a sample of tables from inside a database: [dbo].[DogLocations], [dbo].[DogPrices], [dbo].[Dogs]. The code below would make 3 separate tables for each input that contains all the information I need.
EXEC sp_spaceused @objname = N'[dbo].[DogLocations]'
EXEC sp_spaceused @objname = N'[dbo].[DogPrices]'
EXEC sp_spaceused @objname = N'[dbo].[Dogs]'
How could I get this information from all tables in the database without inputting each table individually, and merge all the output tables into one?