![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| ||||
| ||||
|
|
I need to add a new varchar(8) column that is not null to the primary key. |
|
abusing it). Here is the code I'm using now.. it basically adds the column 'institution_id' as not null along with a default. Then I jump through a couple of hoops trying to get rid of the default. Finally I setup the primary key again. I can only feel I'm supposed to be maybe using a constraint column with a name to do this easier/more properly. |
|
set @dynamicsql = ' alter table institution_xref add institution_id varchar(60) not null default ''' + @default_institution_id + ''' ' |
|
EXEC (@dynamicsql) |
#3
| |||
| |||
|
|
Jeff Kish (jeff.kish (AT) mro (DOT) com) writes: I need to add a new varchar(8) column that is not null to the primary key. Ouch! That can be paintful, at least if there are foreign keys referencing the table. abusing it). Here is the code I'm using now.. it basically adds the column 'institution_id' as not null along with a default. Then I jump through a couple of hoops trying to get rid of the default. Finally I setup the primary key again. I can only feel I'm supposed to be maybe using a constraint column with a name to do this easier/more properly. Yes, if you name the constraint it's a little easier: set @dynamicsql = ' alter table institution_xref add institution_id varchar(60) not null default ''' + @default_institution_id + ''' ' ...not null CONSTRAINT my_temp_default DEFAULT ''' ... EXEC (@dynamicsql) ALTER TABLE ... DROP CONSTRAINT my_temp_default thanks. much! |
![]() |
| Thread Tools | |
| Display Modes | |
| |