User Tools

Site Tools


notes:sql:createdb

CREATE DATABASE

-- 'MyDatabase' - database name
-- The folder(s) for database files must already exist on the server (i.e. C:\Data)
-- The size of the log file is initialized to roughly half of the size of the data file
-- The data file and the log must have different logical names
USE master
GO
CREATE DATABASE MyDatabase
ON PRIMARY                -- does not need to be specified as the PRIMARY filegroup is a default
-- The first file becomes the primary file
(  NAME = MyDatabase_mdf, -- logical file name; it could be specified as a text string i.e. N'MyDatabase_dat'
   FILENAME = 'C:\Data\MyDatabase.mdf', -- physical file name
   SIZE = 10,             -- MB by default, example: 9024KB
   MAXSIZE = 500,         -- can be specified as unlimited: MAXSIZE=UNLIMITED
   FILEGROWTH = 5 )       -- can be specified as percentage: FILEGROWTH=10%
LOG ON
(  NAME = MyDatabase_ldf,
   FILENAME = 'C:\Data\MyDatabase.ldf',
   SIZE = 5MB,
   MAXSIZE = 250MB,
   FILEGROWTH = 5MB )
GO
USE master
GO
CREATE DATABASE TestDB
ON PRIMARY
(  NAME = TestDB_mdf,              
   FILENAME = 'C:\Temp\TestDB.mdf',
   SIZE = 4MB,                        
   MAXSIZE = 1GB,                     
   FILEGROWTH = 1MB )                  
LOG ON
(  NAME = TestDB_ldf,
   FILENAME = 'C:\Temp\TestDB.ldf',
   SIZE = 2MB,
   MAXSIZE = 512MB,
   FILEGROWTH = 10% )
GO
notes/sql/createdb.txt · Last modified: 2015/06/24 by admin