When you create a new Database, at that time you can mention how much sizeb this database should use initially. That much size your database will use till all of that size don’t get used. In the following figure, new database will use 4MB of size by default, whether it will have that much data in it or not. But once the database gets data of that much size it starts growing its size according to the size of data. ![]()
You can find out how much size your database is using by any of the following methods.
Instructions:
- Using SP_SPACEUSED Stored Procedure
- Using SP_HELPDB Stored Procedure
- Using SYSFILES Table
- This table contains information about the files of the database. By default we have two files, primary .mdf file and the other one is log file. This table contains information about both the files and size as well denoted under size column. The size denoted here is in the 8kb page size, which means the total size of every file is size given by the column multiplied by 8. So, if you just want to find out total size of the database, you can use the following query to get result in Megabytes.
USE HowToIdeas
SELECT SUM(size) * 8 / 1024 FROM SYSFILES
- This table contains information about the files of the database. By default we have two files, primary .mdf file and the other one is log file. This table contains information about both the files and size as well denoted under size column. The size denoted here is in the 8kb page size, which means the total size of every file is size given by the column multiplied by 8. So, if you just want to find out total size of the database, you can use the following query to get result in Megabytes.
- Using SYS.DATABASE_FILES Table
- This table is quite similar to SYSFILES and stores result of every database file. You can calculate the resultant size the same way as above table.
USE HowToIdeas
SELECT SUM(size) * 8 / 1024 FROM SYS.DATABASE_FILES
- This table is quite similar to SYSFILES and stores result of every database file. You can calculate the resultant size the same way as above table.