I need to execute stored procedure sp_spaceused for all the tables in my database.
I have used cursor for this, please find the below query.The thing is I need to generate report in a single result set.
For the below query I’m getting different results.
Declare @Name Varchar(500)
Declare @GetName Cursor
Set @Getname = Cursor for
select name from sys.tables
Open @Getname
Fetch Next From @Getname into @Name
While @@Fetch_Status=0
Begin
exec sp_spaceused @Name
Fetch Next From @Getname into @Name
End
Close @GetName
Deallocate @GetName
You can use something like the below (the data types may well need tweaking).
Edit: Please see Joe’s answer for the correct data types to use!