2012年2月18日星期六

Any harm in changing nullability while a default exists for a colu

Hi,
In Microsoft SQL Server 2000 SP3 are there any potential drawbacks of
changing the table column nullability via the ALTER TABLE ALTER COLUMN while
a default is also defined for that column? If yes, what are they?
--
Many thanks,
OskarYou'll need to drop the default constraint before ALTER TABLE...ALTER COLUMN
and re-add the constraint afterwards.
Column nullability doesn't affect the behavior of the default constraint so
I'm not aware of any drawbacks. The default value is used only when the
column is not included in the column list of an INSERT statement. Of
course, an explicit NULL value will be permitted only when the column allows
nulls.
Hope this helps.
Dan Guzman
SQL Server MVP
"Oskar" <Oskar@.discussions.microsoft.com> wrote in message
news:D50EF76B-BF46-4B49-9AD9-07364BF75E8A@.microsoft.com...
> Hi,
> In Microsoft SQL Server 2000 SP3 are there any potential drawbacks of
> changing the table column nullability via the ALTER TABLE ALTER COLUMN
> while
> a default is also defined for that column? If yes, what are they?
> --
> Many thanks,
> Oskar
>|||Yes, but when I needed to change a column from NULL to NOT NULL in one of the
tables and a default was defined on that column, the SQL Server parser didn't
complain about that. It allowed me to change the definition without any
warnings. Does this mean that I've done it in the wrong way? If yes, why?
--
Many thanks,
Oskar
"Dan Guzman" wrote:
> You'll need to drop the default constraint before ALTER TABLE...ALTER COLUMN
> and re-add the constraint afterwards.
> Column nullability doesn't affect the behavior of the default constraint so
> I'm not aware of any drawbacks. The default value is used only when the
> column is not included in the column list of an INSERT statement. Of
> course, an explicit NULL value will be permitted only when the column allows
> nulls.
>
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> "Oskar" <Oskar@.discussions.microsoft.com> wrote in message
> news:D50EF76B-BF46-4B49-9AD9-07364BF75E8A@.microsoft.com...
> > Hi,
> > In Microsoft SQL Server 2000 SP3 are there any potential drawbacks of
> > changing the table column nullability via the ALTER TABLE ALTER COLUMN
> > while
> > a default is also defined for that column? If yes, what are they?
> >
> > --
> > Many thanks,
> > Oskar
> >
> >
>
>|||No, Oskar, you didn't do anything wrong. My comment about dropping and
re-adding the constraint applies when changing the column data type but not
when changing only column nullability. Sorry for the confusion.
--
Hope this helps.
Dan Guzman
SQL Server MVP
"Oskar" <Oskar@.discussions.microsoft.com> wrote in message
news:3049DDD6-BA64-4A17-BEB6-7B34B9C68D80@.microsoft.com...
> Yes, but when I needed to change a column from NULL to NOT NULL in one of
> the
> tables and a default was defined on that column, the SQL Server parser
> didn't
> complain about that. It allowed me to change the definition without any
> warnings. Does this mean that I've done it in the wrong way? If yes, why?
> --
> Many thanks,
> Oskar
> "Dan Guzman" wrote:
>> You'll need to drop the default constraint before ALTER TABLE...ALTER
>> COLUMN
>> and re-add the constraint afterwards.
>> Column nullability doesn't affect the behavior of the default constraint
>> so
>> I'm not aware of any drawbacks. The default value is used only when the
>> column is not included in the column list of an INSERT statement. Of
>> course, an explicit NULL value will be permitted only when the column
>> allows
>> nulls.
>>
>> --
>> Hope this helps.
>> Dan Guzman
>> SQL Server MVP
>> "Oskar" <Oskar@.discussions.microsoft.com> wrote in message
>> news:D50EF76B-BF46-4B49-9AD9-07364BF75E8A@.microsoft.com...
>> > Hi,
>> > In Microsoft SQL Server 2000 SP3 are there any potential drawbacks of
>> > changing the table column nullability via the ALTER TABLE ALTER COLUMN
>> > while
>> > a default is also defined for that column? If yes, what are they?
>> >
>> > --
>> > Many thanks,
>> > Oskar
>> >
>> >
>>

没有评论:

发表评论