Pr.Pg Next Pg

To create a database using T-SQL tutorials

  • Below is an example of Transact-SQL statements required to create a database using QUERY.

  • Select SSMS – File menu – New – Query with Current Connection.

  • Command to create Database is as follow.

 

Syntax to Create Database

CREATE DATABASE <database_name>

ON

(

NAME = <primary_datafile_name>,

FILENAME = '<path\primary_datafile_name>.mdf',

SIZE = <primary_datafile_size_in_MB>,

MAXSIZE = <primary_datafile_maximum_size_in_MB>,

FILEGROWTH = <primary_datafile_filegrowth_size_as_a_%>

),

 

(

NAME = <secondary_datafile_name>,

FILENAME = '<path\secondary_datafile_name>.ndf',

SIZE = <secondary_datafile_size_in_MB>,

MAXSIZE = <secondary_datafile_maximum_size_in_MB>,

FILEGROWTH = <secondary_datafile_filegrowth_size_as_a_%>

),

 

LOG ON

(

NAME = <log_file_name>,

FILENAME = '<path\logical_file_name>.ldf',

SIZE = <log_file_size_in_MB>,

MAXSIZE = <log_file_maximum_size_in_MB>,

FILEGROWTH = <log_file_filegrowth_size_as_a_%>

)

 

For example

CREATE DATABASE TESTDATA

ON

( NAME = TESTDB_DATA,

FILENAME = ‘D:\SQLDATA\TESTDB_DATA.mdf’ ,

SIZE = 100MB,

MAXSIZE = 1GB,

FILEGROWTH = 10MB),

LOG ON

( NAME = TESTDB_LOG,

FILENAME = ‘D:\SQLDATA\TESTDB_LOG.ldf’ ,

SIZE = 20MB,

MAXSIZE = 1GB,

FILEGROWTH = 10MB)

 

 

Here is Simple command example with default options to create Database.

CREATE DATABASE cbtSAM_test;

CREATE DATABASE ACCOUNT2012;

CREATE DATABASE TOYOTAPURCHASE2012;

 


 

Pr.Pg border                                              Next Pg