DDL (Data Definition Language ) Commands.

DDL (Data Definition Language ) Commands:

DDL Commands are used to create or destroy the objects in SQL Server.

  • Create
  • Alter
  • Drop
  • Create Command
    • To create a table to use fallowing syntax:

 

Syntax:

Create  table  <table-name> (column-1   datatype,

column-2   datatype,

column-3   datatype,

———————

———————

Column-n  datatype, primary key(one or more columns))

Example:

Create  table  Student(sno int, sname varchar(40), gender varchar(6),marks int, primary key(sno))

  • Alter Command
  • By The use of ALTER TABLE Command we can modify our exiting table.

Add new column’s to the existing table

Syntax:

Alter  table  <table-name>  add   <new column name>  datatype(size), . . . . . . . . . . . n)

Example:

alter  table   student  add  column age

 

  • Student table is already exists and then we can add one new column age to the student table.

 

Increasing the width of Column:

Syntax:   alter  table  <tab-name>  alter column  <col-name> datatype (size)

Example:              alter table student alter column name varchar(50)

 

  • Initially name column size is 40 and increased to 50

Decreasing the width of Column:

Syntax:   alter  table  <tab-name>  alter column  <col-name> datatype (size)

Example:            alter table student alter column name varchar(50)

 

  • Initially name column size is 40 and decreased to 30

Drop a column from existing table

Syntax:                       alter  table   student  drop  column age

 

Example: alter   table  Student drop column  age

  • Drop Command
  • Drop command is used to drop the table.

Syntax:   drop table <table-name>

Example:   drop table student

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s