adding a default constraint to an existing column in sql

Solutions on MaxInterview for adding a default constraint to an existing column in sql by the best coders in the world

showing results for - "adding a default constraint to an existing column in sql"
Hywel
22 Aug 2016
1--Altering an existing column to add a default constraint:
2ALTER TABLE {TABLE NAME}
3ADD CONSTRAINT {CONSTRAINT NAME}
4DEFAULT {DEFAULT VALUE} FOR {EXISTING COLUMN NAME}
5
6--Adding a new column, with default value, to an existing table:
7ALTER TABLE {TABLE NAME}
8ADD {COLUMN NAME} {DATA TYPE} {NULL | NOT NULL}
9CONSTRAINT {CONSTRAINT NAME} DEFAULT {DEFAULT VALUE}
10
11--Dropping a contraint:
12ALTER TABLE {TABLE NAME}
13DROP CONSTRAINT {CONSTRAINT NAME}