I am trying to find the space used by a database through the sqlcmd utility. I used sp_spaceused command to get the details of the database size. Now i want to store only the available size (i.e unallocated space) to a variable .
I think the output is not correctly formatted while pasting , i haved added an image for reference . out.txt
This is my batch script :
echo off
sqlcmd -E -S <machinename> -i findspaceused.sql -o out.txt
set /p delExit=Press the ENTER key to exit...:
This is my sql file :
USE KCC;
EXEC sp_spaceused @oneresultset = 1;
The output of the batch script :
Changed database context to 'KCC'.
database_name database_size unallocated space reserved data index_size unused
-------------------------------------------------------------------------------------------------------------------------------- ------------------ ------------------ ------------------ ------------------ ------------------ ------------------
KCC 16.00 MB 4.11 MB 3984 KB 1456 KB 1416 KB 1112 KB