The error message:
Cannot insert the value NULL into column 'C_NUM', table 'tempdb.dbo.#TEST________________________________________________________
___________________________________________________
____000000000005'; column does not allow nulls. UPDATE fails.
I believe this error is on line
INSERT INTO #TEST (XX000, C_NUM) VALUES (2, NULL)
Thank you.
>Hi,
>
> Please, can you run this example in MSSMS?
>
>
>CREATE TABLE #TEST (XX000 INT NOT NULL, C_NUM decimal (15,2) NULL DEFAULT 0)
>INSERT INTO #TEST (XX000, C_NUM) VALUES (0,1)
>INSERT INTO #TEST (XX000) VALUES (1)
>INSERT INTO #TEST (XX000, C_NUM) VALUES (2, NULL)
>SELECT * FROM #TEST
>ALTER TABLE #TEST ALTER COLUMN C_NUM decimal (20,5) not null
>
>
>
>MartinaJ
>
>
>>>>Hi,
>>>>
>>>>I am testing the following Alter command (in SSMS)
>>>>
>>>>alter TableName Alter ColumnName numeric (12,2) not null
>>>>
>>>>The result I get is what I want: the column size changes, it is not null, and The Default is set to 0 (which I did not specify above).
>>>>Is Default set to 0 (zero) by design because my expressing says Not Null?
>>>>
>>>>TIA
>>>
>>>If you have set DEFAULT before altering the column usually must drop the constraint, alter column and then put the constraint back.
>>>I got to many errors from different versions of SQL Server when I tried to alter columns so I choose this approach.
>>>Maybe different versions handle this differently but I don't risk anymore.
>>
>>The column had the DEFAULT set before I made the change of the column size. And I do prefer not to change the default. Do I understand correctly that the DEFAULT will stay the way it was before I change the size?
>>Thank you.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham