Reply to Re: best way to add column not null

Your name:

Reply:


Posted by Jeff Kish on 06/06/07 14:20

On Tue, 5 Jun 2007 22:28:21 +0000 (UTC), Erland Sommarskog
<esquel@sommarskog.se> wrote:

>Jeff Kish (jeff.kish@mro.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!
Jeff Kish

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация