Quantcast
Viewing all articles
Browse latest Browse all 91

Answer by Akhil Singh for How to add a column with a default value to an existing table in SQL Server?

This is for SQL Server:

ALTER TABLE TableNameADD ColumnName (type) -- NULL OR NOT NULLDEFAULT (default value)WITH VALUES

Example:

ALTER TABLE ActivitiesADD status int NOT NULL DEFAULT (0)WITH VALUES

If you want to add constraints then:

ALTER TABLE Table_1ADD row3 int NOT NULLCONSTRAINT CONSTRAINT_NAME DEFAULT (0)WITH VALUES

Viewing all articles
Browse latest Browse all 91

Trending Articles