Add and Drop New not null column in Sql

In this lesson we are going to see how to add new column with default value.This situation arrives sometimes  we need to add a field in primary key or some others.So here i will explain it.

1.Add Column
ALTER TABLE  table name ADD column name  datatype DEFAULT  default value NOT NULL


(e.g)

  • alter table customer add  customer_type tinyint default 1 not null
  • alter table test add age int not null default 1




2.Drop column

 ALTER TABLE table name ALTER COLUMN column name  datatype NULL

(e.g)
alter table customer alter column customer_type tinyint null


I hope this will be helpful for you.

Comments

Popular posts from this blog

Types of Architects

Basic measurements

Search html table contents based on its td using Jquery