Tags

, , ,


Today I am going to write about a very simple topic  – how we can add a column to an existing table with a default constraint. I will show how to name the constraint  while creating it.

For demonstration, I have created a dummy table called ‘Product’. Lets see all the columns of Product table along with few sample records:

SELECT * FROM Product

Now, lets add the column with Default constraint:

ALTER TABLE Product
ADD Price DECIMAL(18,2)
CONSTRAINT DF_Product_Price DEFAULT 0.00 NOT NULL

Now, lets check the values of the table again:

SELECT * FROM Product

This is pretty easy.Isn’t it?

Thanks,

Subhro Saha

 

Advertisements