Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
mdanwerali
Starting Member
30 Posts |
Posted - 2002-12-04 : 03:11:37
|
| Hi,I have already 50 tables with lots of data in it, now i got a new requirement for adding Default Constraint to few tables.When i am trying this using ALTER TABLE ALTER COLUMN ADD CONSTRAINTS.. then it is gining error, then i read Sql Server help in that, they have not mentioned how to add Default Constraint to an existing Column, but we can add while adding a new column.but what i want is without data lost i was to add default constraint to my table.plz helpAnwer |
|
|
mr_mist
Grunnio
1870 Posts |
Posted - 2002-12-04 : 03:22:16
|
Your syntax is wrong. From BOL Alter Table :quote: D. Alter a table to add an unverified constraintThis example adds a constraint to an existing column in the table. The column has a value that violates the constraint; therefore, WITH NOCHECK is used to prevent the constraint from being validated against existing rows, and to allow the constraint to be added.CREATE TABLE doc_exd ( column_a INT) GOINSERT INTO doc_exd VALUES (-1)GOALTER TABLE doc_exd WITH NOCHECK ADD CONSTRAINT exd_check CHECK (column_a > 1)GOEXEC sp_help doc_exdGODROP TABLE doc_exdGO
-------Moo. |
 |
|
|
Andraax
Aged Yak Warrior
790 Posts |
Posted - 2002-12-04 : 03:27:10
|
| Or a more specific example...ALTER TABLE MyTable ADD CONSTRAINT DF_MyTable_MyColumn DEFAULT MyValue FOR MyColumn |
 |
|
|
mdanwerali
Starting Member
30 Posts |
Posted - 2002-12-04 : 06:22:11
|
thank you very much.it is working perfectly. quote: Or a more specific example...ALTER TABLE MyTable ADD CONSTRAINT DF_MyTable_MyColumn DEFAULT MyValue FOR MyColumn
|
 |
|
|
|
|
|