Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Add a column, with a default value, to an existing table in SQL Server

Add a Column, with a Default value, to an existing table in SQL Server

Syntax:

ALTER TABLE TABLE_NAME
            ADD COL_NNAME COL_TYPE {NOT NULL OR NULL}
                        CONSTRAINTCONSTRAINT_NAME
                                    DEFAULT DEFAULT_VALUE
WITH VALUES

For example

ALTER TABLE CUSTOMER
            ADD NAME VARCHAR (255) NOT NULL
                        CONSTRAINTCUSTOMER_CONSTRAINT_NAME
                                    DEFAULT 'PENDING CUSTOMER'
WITH VALUES

In the above query "WITH VALUES" handles the "not null".

Share the post

Add a column, with a default value, to an existing table in SQL Server

×

Subscribe to Angular 2 Javascript Asp.net C# Sql Server Knockoutjs Angularjs Kendo Ui Html 5 Web Api Wpf Wcf Etc.

Get updates delivered right to your inbox!

Thank you for your subscription

×