Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add a column, with a default value, to an existing table in SQL Server 2008 or 2012? [duplicate]

How do I add a column, with a default value, to an existing table in SQLServer 2008?

like image 508
Mahendra Sahu Avatar asked Jun 05 '13 06:06

Mahendra Sahu


People also ask

How can a column with a default value be added to an existing table?

To add a new column to an existing table, we use the ALTER TABLE command to add a new column to an existing. To set a default value, we use the DEFAULT constraint.

How do you add a column and insert value to an existing table in SQL?

INSERT INTO Syntax Specify both the column names and the values to be inserted: INSERT INTO table_name (column1, column2, column3, ...)


1 Answers

ALTER TABLE {TABLENAME} ADD {COLUMNNAME} {TYPE} {NULL|NOT NULL} CONSTRAINT {CONSTRAINT_NAME} DEFAULT {DEFAULT_VALUE}

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

like image 56
Pritesh Tayade Avatar answered Sep 27 '22 21:09

Pritesh Tayade