Pages

Saturday 11 June 2011

DDL Statements in SQL Server.

1 comments
 
Hi friends,in this post i would like to explain DDL commands in SQL Server.

There are 3 types of DDL commands exist:

1)CREATE 2)ALTER 3)DROP

1)CREATE : For creating databases & database objects.

Syntax for creating database:

CREATE DATABASE DataBaseName

For Ex:

Create DataBase College


Syntax for creating Table:

CREATE TABLE TableName
(Column1 datatype,
Column2 datatype,
.......
.......)

For Ex:

Create Table Employee
(EmpId int,EmpName varchar(50),Salary money)


2)ALTER : For altering the exsisting tables.

Syntax for adding columns:

Alter Table TableName Add Column1 datatype,Column2 datatype,.....

For Ex:

Alter Table Employee Add DateOfJoin datetime,Address varchar(300)

Syntax for changing column datatype:

Alter Table TableName Alter Column ColumnName NewDataType

For Ex:

Alter Table Employee Alter Column EmpId BigInt

Syntax For Droping Columns:

Alter Table TableName Drop Column Column1,Column2,.....

For Ex:

Alter Table Employee Drop Column DateOfJoin,Address


3)DROP : is used for droping database & database objects.

Syntax for droping Tables:

Drop Table table1,table2,...

For Ex:

Drop Table Employee

Syntax for droping databases:

Drop DataBase database1,database2,...

For Ex:

Drop DataBase College

Note:

* We can't drop current(working) database.
* We can't drop system databases(i.e Master,Model,Msdb,Tempdb).



Thank You...
Shout it

One Response so far.

  1. Excellent pieces. Keep posting such kind of information on your blog. I really impressed by your blog.

Leave a Reply