Database Creation


When you create database, two or more database files are created. Because each database must have at least one data file [.mdf] (used for storing database objects) and one log file [.ldf] (used for storing transaction information).

Simple way to Create databas:

CREATE DATABASE [customer];

It will create database with default path

Customize way:

USE [master]
GOCREATE DATABASE [customer] ON  PRIMARY(NAME = N'customer',
FILENAME = N'D:\customer.mdf' ,
SIZE = 548864KB ,MAXSIZE = UNLIMITED,FILEGROWTH = 1024KB
)
 LOG ON( NAME = N'customer_log',
  FILENAME = N'D:\customer_log.ldf' ,  SIZE = 470144KB ,
  MAXSIZE = 2048GB ,
  FILEGROWTH = 10%
)GO

What is master here?
  •  Master is the database that records the existence of all other databases and the location of those database files and records the initialization information for SQL Server.
  • CREATE DATABASE database_name is used to create database.
  • ON specifies that the disk files used to store the data sections of the database, data files, are explicitly defined.
  • PRIMARY defines attributes for primary data file as 
            NAME: defines logical file name.
              FILENAME: defines physical File name (Location of datafile)
       SIZE : defines size of file.
        MAXSIZE : defines maximum size of file to which datafile can     grow.
       FILEGROWTH: defines growth increment in file.

  • LOG : defines attribultes for log file.


A detail description of database creation can be found Here.




Prev--->Control Statements in T-SQL                    Next--->Stored Procedure in T-SQL

No comments:

Post a Comment

Please leave a comment for this post