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 |
|
MyronCope
Starting Member
46 Posts |
Posted - 2007-04-16 : 15:11:09
|
| Hi,I have a bit field that I will just call FieldA for now, anyways, I need to write a script that will modify the bitfield so that when a new record is created in that table, lets call it tblSomeTable, that it will set FieldA to False (O).Thanks |
|
|
pootle_flump
1064 Posts |
Posted - 2007-04-16 : 15:18:35
|
| [code]ALTER TABLE tblSomeTableADD FieldA BIT --NOT NULLCONSTRAINT df_tblSomeTable_FieldA DEFAULT (0)[/code]Comment out the NOT NULL if you don't want nulls. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2007-04-16 : 15:23:29
|
| I think he just needs the constraint since the column already exists, or at least that's how I read it.ALTER TABLE tblSomeTable ADD CONSTRAINT df_tblSomeTable_FieldA DEFAULT (0)Tara Kizerhttp://weblogs.sqlteam.com/tarad/ |
 |
|
|
pootle_flump
1064 Posts |
Posted - 2007-04-16 : 15:25:29
|
Ah! Whoops a daisy.Does that work though? Column name not specified....ALTER TABLE tblSomeTableADD CONSTRAINT df_tblSomeTable_FieldA DEFAULT 0 FOR FieldA |
 |
|
|
MyronCope
Starting Member
46 Posts |
Posted - 2007-04-16 : 15:30:18
|
| Yes, tk, the field already exists, i just want to set the default value to 0, thanks much to both of you |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-04-16 : 15:41:41
|
| You may also think about adding the WITH VALUESif you intend to default all existing null values to 0.Peter LarssonHelsingborg, Sweden |
 |
|
|
|
|
|