Home All Groups Group Topic Archive Search About

Modifying table issue



Author
24 Jun 2009 5:27 PM
John
Hi

When I try to modify a Bit field's Allow Null to No, I get the message that
change can not be made without dropping the table. The table contains data.
How can I make this change while maintaining the data in the table?

Thanks

Regards

Author
24 Jun 2009 5:53 PM
Rick Sawtell
"John" <info@nospam.infovis.co.uk> wrote in message
news:u0Ws7DP9JHA.5064@TK2MSFTNGP03.phx.gbl...
> Hi
>
> When I try to modify a Bit field's Allow Null to No, I get the message
> that change can not be made without dropping the table. The table contains
> data. How can I make this change while maintaining the data in the table?
>
> Thanks
>
> Regards
>
>

If you do not have any NULL values in the table, then you can simply do the
following:

ALTER TABLE <tablename> ALTER COLUMN <bit column name> bit NOT NULL


If you do have nulls already in the table, then you must either update the
null values to 0 or 1 first then run the code above.


Your other option is to create a CHECK CONSTRAINT as in this example.


ALTER TABLE <tablename> WITH NOCHECK ADD CONSTRAINT <constraint name> CHECK
(<bit column name> IS NOT NULL)


I hope this helps.

Rick Sawtell
MCT, MCSD, MCDBA, MCITPro
Are all your drivers up to date? click for free checkup

Author
24 Jun 2009 6:07 PM
John
Hi

When ALTER Command is used it works fine. However when using the graphic
designer I get the error. Strange.

Thanks

Regards

Show quoteHide quote
"Rick Sawtell" <r_sawtell@nospam.hotmail.com> wrote in message
news:%230omsSP9JHA.1488@TK2MSFTNGP03.phx.gbl...
>
> "John" <info@nospam.infovis.co.uk> wrote in message
> news:u0Ws7DP9JHA.5064@TK2MSFTNGP03.phx.gbl...
>> Hi
>>
>> When I try to modify a Bit field's Allow Null to No, I get the message
>> that change can not be made without dropping the table. The table
>> contains data. How can I make this change while maintaining the data in
>> the table?
>>
>> Thanks
>>
>> Regards
>>
>>
>
> If you do not have any NULL values in the table, then you can simply do
> the following:
>
> ALTER TABLE <tablename> ALTER COLUMN <bit column name> bit NOT NULL
>
>
> If you do have nulls already in the table, then you must either update the
> null values to 0 or 1 first then run the code above.
>
>
> Your other option is to create a CHECK CONSTRAINT as in this example.
>
>
> ALTER TABLE <tablename> WITH NOCHECK ADD CONSTRAINT <constraint name>
> CHECK (<bit column name> IS NOT NULL)
>
>
> I hope this helps.
>
> Rick Sawtell
> MCT, MCSD, MCDBA, MCITPro
>
>
>
>
Author
24 Jun 2009 6:16 PM
Tibor Karaszi
By default, the tool will not allow things where the tool thinks it
need to re-create the table (not that you are smarter than the tool
since you know this can be achieved using an ALTER TABLE). You can
configure somewhere in Tools, Option to allow for this. Note, though,
that often the tool isn't as smart as we are (i.e., it does things in
clumsy ways) - so always watch that change script before saving.

Show quoteHide quote
"John" <info@nospam.infovis.co.uk> wrote in message
news:uyGFqaP9JHA.3836@TK2MSFTNGP02.phx.gbl...
> Hi
>
> When ALTER Command is used it works fine. However when using the
> graphic designer I get the error. Strange.
>
> Thanks
>
> Regards
>
> "Rick Sawtell" <r_sawtell@nospam.hotmail.com> wrote in message
> news:%230omsSP9JHA.1488@TK2MSFTNGP03.phx.gbl...
>>
>> "John" <info@nospam.infovis.co.uk> wrote in message
>> news:u0Ws7DP9JHA.5064@TK2MSFTNGP03.phx.gbl...
>>> Hi
>>>
>>> When I try to modify a Bit field's Allow Null to No, I get the
>>> message that change can not be made without dropping the table.
>>> The table contains data. How can I make this change while
>>> maintaining the data in the table?
>>>
>>> Thanks
>>>
>>> Regards
>>>
>>>
>>
>> If you do not have any NULL values in the table, then you can
>> simply do the following:
>>
>> ALTER TABLE <tablename> ALTER COLUMN <bit column name> bit NOT NULL
>>
>>
>> If you do have nulls already in the table, then you must either
>> update the null values to 0 or 1 first then run the code above.
>>
>>
>> Your other option is to create a CHECK CONSTRAINT as in this
>> example.
>>
>>
>> ALTER TABLE <tablename> WITH NOCHECK ADD CONSTRAINT <constraint
>> name> CHECK (<bit column name> IS NOT NULL)
>>
>>
>> I hope this helps.
>>
>> Rick Sawtell
>> MCT, MCSD, MCDBA, MCITPro
>>
>>
>>
>>
>
>

Bookmark and Share