Pages

Social Icons

Saturday 27 October 2012

Add and Drop column from the table

Hi,

Sometimes we have requirement to add or drop a column in a existing Table.

We can drop column using following statement

ADD TABLE table_name
DROP COLUMN column_name;

For adding a column we can use the following statement

ADD TABLE table_name
ADD column_name datatype;

But this column adds in to the table with null value after then we need to update the same column with some default value. We can give the value to the column at the time of adding that using default value constraint with the following statement.

ADD TABLE table_name
ADD column_name datatype DEFAULT(0);

Example :

ADD TABLE Employee
ADD IsActive Bit DEFAULT(0);

Thx,
Rahul

No comments:

Post a Comment