Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Initial size of the database file using T-SQL Expand / Collapse
Author
Message
Posted Tuesday, April 9, 2013 11:19 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Yesterday @ 4:29 PM
Points: 22, Visits: 305
Hi,

Please let me know how to get the initial size of the database file using T-SQL.

sys.master_files, sys.database_files, sysfiles, sysaltfiles --> gives only the current size and not the initial size.


Thanks,
Karthik R
Post #1440652
Posted Wednesday, April 10, 2013 2:05 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Today @ 4:22 AM
Points: 895, Visits: 2,442
I don't believe that the original size is stored anywhere only the current size.

_________________________________________________________________________
SSC Guide to Posting and Best Practices
Post #1440690
Posted Wednesday, April 10, 2013 2:14 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Saturday, October 25, 2014 11:42 AM
Points: 2,380, Visits: 7,591
karthik.catchme (4/9/2013)
Hi,

Please let me know how to get the initial size of the database file using T-SQL.

sys.master_files, sys.database_files, sysfiles, sysaltfiles --> gives only the current size and not the initial size.


Thanks,
Karthik R


IIRC, the size that you initially gave to the database file is not stored anywhere. I think that the "initial size" that you can see when you right click a database in the GUI then click properties and then click files is in fact the current size.

Execute the following: -
SELECT db.name AS [Logical Name],
CASE WHEN db.[type] = 0 THEN 'Rows Data'
ELSE 'Log' END AS [File Type],
(db.size*8)/1024 AS initialSize
FROM sys.database_files db

And I think that you'll see that the "initial size" reported by the query matches the "initial size" in the GUI.



Not a DBA, just trying to learn

For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/

For better, quicker answers on SQL Server performance related questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/



If you litter your database queries with nolock query hints, are you aware of the side effects?
Try reading a few of these links...

(*) Missing rows with nolock
(*) Allocation order scans with nolock
(*) Consistency issues with nolock
(*) Transient Corruption Errors in SQL Server error log caused by nolock
(*) Dirty reads, read errors, reading rows twice and missing rows with nolock


LinkedIn | Blog coming soon (for sufficiently large values of "soon" )!
Post #1440693
Posted Wednesday, April 10, 2013 8:26 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Yesterday @ 4:29 PM
Points: 22, Visits: 305
Books online states that shrinkdatabase cannot shrink smaller than its original size. So, how does SQL Server know the initial size / original size of the database without saving it in any of the system tables?

When using the DBCC SHRINKDATABASE statement, you cannot shrink a whole database to be smaller than its original size. Therefore, if a database was created with a size of 10 MB and grew to 100 MB, the smallest the database could be reduced to is 10 MB, even if all the data in the database has been deleted.
Post #1440840
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse