Labels

Wednesday, 16 December 2015

Database creation in SQL Server

We can create a database in SQL Server in 2 methods .

                                                     1. Using GUI
                                                     2. Using T-SQL

Method 1 : Using GUI

Step 1:  Connect to SQL Server using WIN + R --> SSMS --> Enter IP / . --> Right click on Database
             --> New Database



Step 2 : Type database name as GUIMethod --> Click OK .


Step 3 : Now the database is created with the name GUIMethod as shown below .



Method 2 : Using T-SQL

Syntax to create new database :

USE Master
GO

CREATE DATABASE < DATABASE NAME > ON PRIMARY 
(
 NAME = < DATABASE NAME >
        FileName = < mdf file path location >
 ,SIZE = < Required size >
        , MaxSize = < Required Size > 
        ,FileGrowth = < Required Size >
) 
ON log 
(
 NAME = < DATABASE NAME > 
        FileName = < ldf file path location >
 ,SIZE = < Required size > 
        ,MaxSize = < Required Size >
        ,FileGrowth = < Required Size >
)

Ex:

USE Master
GO
USE master; GO CREATE DATABASE Sales ON ( NAME = TSQL ,FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\TSQL.mdf' ,SIZE = 10 ,MAXSIZE = 50 ,FILEGROWTH = 5 ) LOG ON ( NAME = Sales_log ,FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\TSQL.ldf' ,SIZE = 5 MB ,MAXSIZE = 25 MB ,FILEGROWTH = 5 MB );

No comments:

Post a Comment