The simplest way to create a database in SQL Server is to use CREATE DATABASE my_database
without specifying anything else. When you do this, data files and log files are created in the default location (see how to find the default location).
However, sometimes you might want the data files and log files to reside in a different location. If that’s the case, use the following code example to explicitly state your own location for the database’s data files and log files.
USE master;
GO
CREATE DATABASE Solutions
ON
( NAME = Solutions_dat,
FILENAME = 'D:\mssql\data\Solutionsdat.mdf',
SIZE = 10MB,
MAXSIZE = 50MB,
FILEGROWTH = 5MB )
LOG ON
( NAME = Solutions_log,
FILENAME = 'D:\mssql\data\Solutionslog.ldf',
SIZE = 5MB,
MAXSIZE = 25MB,
FILEGROWTH = 5MB );
GO
That example uses Windows path conventions (starts with a drive letter and uses a backslash).
Continue reading →