Home

Database Crestion Examples

   

Overview

These are examples of creating a database in Transact-SQL.

 

Simple Example

Here is an example:

CREATE DATABASE NationalCensus;

Specifying the Primary File Group

The formula is:

CREATE DATABASE DatabaseName
ON PRIMARY
( NAME = LogicalName, FILENAME = Path )

Here is an example:

CREATE DATABASE NationalCensus
ON PRIMARY
( NAME = DataRepository, FILENAME = 'C:\Exercises\NationalCensus.mdf')
GO

Specifying a Primary and One Secondary File Groups

The formula is:

CREATE DATABASE DatabaseName
ON PRIMARY
( NAME = LogicalName, FILENAME = Path.mdf )
LOG ON
( NAME = LogicalName, FILENAME = Path.ldf )

Here is an example:

CREATE DATABASE NationalCensus
ON PRIMARY
( NAME = DataRepository, FILENAME = 'C:\Exercises\NationalCensus.mdf')
LOG ON
( NAME = DataLog, FILENAME = 'C:\Exercises\NationalCensus.ldf')
GO

Specifying a Primary, Many Secondary File Groups, and a Log File

Here is an example:

CREATE DATABASE KoloBank
ON PRIMARY
  ( NAME = N'KoloBankMain',
    FILENAME = N'C:\Kolo Bank Primary\KoloBankMain.mdf',
    SIZE = 100MB,
    MAXSIZE = 500MB,
    FILEGROWTH = 10MB),
FILEGROUP KoloBankPrimary
  ( NAME = N'KoloBankFirst',
    FILENAME = N'C:\Kolo Bank Primary\KoloBankFirst.ndf',
    SIZE = 20MB,
    MAXSIZE = 100MB,
    FILEGROWTH = 2MB),
FILEGROUP KoloBankSecondary
  ( NAME = N'KoloBankSecond',
    FILENAME = N'D:\Kolo Bank Secondary\KoloBankSecondady.ndf',
    SIZE = 20MB,
    MAXSIZE = 100MB,
    FILEGROWTH = 2MB)
LOG ON
  ( NAME = N'KoloBankLog',
    FILENAME = N'C:\Kolo Bank Logs\KoloBankLogger.ldf',
    SIZE = 10MB,
    MAXSIZE = 20MB,
    FILEGROWTH = 2MB);
GO
 
 
 
     
 

Home Copyright © 2007-2011 FunctionX.com