We can create a database simply by typing in the command
create database DB1
We don’t have to provide any other parameters for SSMS to be able to create the database
My Question is from where does SQL get the default values when we create a database without any options?
We have always assumed that is was from the model database.
Here’s an interesting exercise:
Create an empty database using the command above and make a note of its size and autogrowth values.
Compare these to those of the model database. Assuming you have never changed the model database you’ll find they are identical.
Change the initial size and the autogrowth values in the model database to something obviously different.
Now create a new database DB2 with the script
create database DB2
Take a look at the size and autogrowth of the new database and compare them to the values you put in the model database. The data file size will probably match but the rest will have taken the original values you saw in the model database.
SSMS hasn’t used the values in the model database which is what we all assumed it would do
Now create a database using the GUI
You will see in the GUI that the new database has taken its values from the model database
It seems that SSMS only uses the model database as its template when you use the GUI, you cannot guarantee the values that will be used when using a simple script
Which is why its best practice is to include all the parameters when creating database.
In case you need to reset mode back to the SQL defaults then run this
USE [model]
GO
DBCC SHRINKFILE (N'modeldev' , 3)
GO
DBCC SHRINKFILE (N'modellog' , 1)
GO
USE [master]
GO
ALTER DATABASE [model] MODIFY FILE ( NAME = N'modeldev', FILEGROWTH = 1024KB )
GO
ALTER DATABASE [model] MODIFY FILE ( NAME = N'modellog', FILEGROWTH = 10%)