When adding a .MDF
(.NDF
) or .LDF
file to a SQL Server, we have the option to set its initial size, auto-growth, and incremental (percent or absolute).
After the database is in operation for a while, is it possible find how much of the actual size is used by the data? For example, if the actual size of the file is 5M, but only 2M is used to store the data, the file can still take 3M of data before it needs to grow.
I need a way to find out the "2M" (used size) in the total current size (5M) of the file.
After some research, I noticed the
FILEPROPERTY
function.It seems to give me how much being used within the current size of the file. For example, if the current size of the file is 5M, the
FILEPROPERTY()
may give me 2M, which means that the file can still take 3M of data before it needs to grow.If anyone can confirm with me, I will mark it as the answer.
How to find the SQL log file(.ldf) size
If you have created the database with your own specific initial size parameter then NO, there is no way of knowing it unless, if you have scripted the db creation.
Otherwise, generally the default initial size is considered to be same as
model
database. So, if it's default then you can check withmodel
database initial size which generally is3MB
and
Use them like this:
Someone correct me if i'm wrong but for the data file I believe an *uncompressed backup should roughly correspond to the actual amount of data in the file. For example if the database is 2gb but the backup is 1gb you have ~1gb of data. As far as the log you're on your own.