August 27, 2010 at 6:20 am
Hi there,
I need a script to change a TINYINT (not null default 0) TO DECIMAL(6,3).
These are my results:
ALTER TABLE systeem ALTER COLUMN aantal_dagen_vooruit_in_te_plannen DECIMAL(6,3) NOT NULL DEFAULT 0
Incorrect syntax near the keyword 'DEFAULT'
ALTER TABLE systeem ALTER COLUMN aantal_dagen_vooruit_in_te_plannen DECIMAL(6,3) NOT NULL
Msg 5074, Level 16, State 1, Line 1
The object 'DF_systeem_aantal_dagen_vooruit_in_te_plannen1' is dependent on column 'aantal_dagen_vooruit_in_te_plannen'.
Msg 4922, Level 16, State 9, Line 1
ALTER TABLE ALTER COLUMN aantal_dagen_vooruit_in_te_plannen failed because one or more objects access this column.
Anyone?
August 27, 2010 at 6:35 am
r.vanlaake-1086273 (8/27/2010)
Hi there,I need a script to change a TINYINT (not null default 0) TO DECIMAL(6,3).
These are my results:
ALTER TABLE systeem ALTER COLUMN aantal_dagen_vooruit_in_te_plannen DECIMAL(6,3) NOT NULL DEFAULT 0
Incorrect syntax near the keyword 'DEFAULT'
ALTER TABLE systeem ALTER COLUMN aantal_dagen_vooruit_in_te_plannen DECIMAL(6,3) NOT NULL
Msg 5074, Level 16, State 1, Line 1
The object 'DF_systeem_aantal_dagen_vooruit_in_te_plannen1' is dependent on column 'aantal_dagen_vooruit_in_te_plannen'.
Msg 4922, Level 16, State 9, Line 1
ALTER TABLE ALTER COLUMN aantal_dagen_vooruit_in_te_plannen failed because one or more objects access this column.
Anyone?
You need to drop the existing default before changing the column. How does this work?
ALTER TABLE systeem DROP CONSTRAINT [DF_systeem_aantal_dagen_vooruit_in_te_plannen1]
GO
ALTER TABLE systeem ALTER COLUMN aantal_dagen_vooruit_in_te_plannen DECIMAL(6,3) NOT NULL DEFAULT (0)
GO
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
August 27, 2010 at 6:48 am
Thanks... but it is not 100% working for me! The constraint gets dropped, but when I try to recreate the column I get the message:
[font="Courier New"]ALTER TABLE systeem ALTER COLUMN aantal_dagen_vooruit_in_te_plannen DECIMAL(6,3) NOT NULL DEFAULT 0
Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'DEFAULT'.[/font]
When I do it without the DEFAULT 0 it does work....
[font="Courier New"]ALTER TABLE systeem ALTER COLUMN aantal_dagen_vooruit_in_te_plannen DECIMAL(6,3) NOT NULL
Command(s) completed successfully.[/font]
must I add the default seperately?
August 27, 2010 at 7:30 am
I think the default needs parenthesis around the value:
DEFAULT (0), not DEFAULT 0
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
August 27, 2010 at 8:11 am
Thanks again for y'r reply, but I already tried that without luck...
August 27, 2010 at 9:04 am
After playing around with this a bit, yes it needs to be done separately. It can be combined on the CREATE TABLE, but not on the ALTER TABLE.
So:
ALTER TABLE systeem DROP CONSTRAINT [DF_systeem_aantal_dagen_vooruit_in_te_plannen1];
GO
ALTER TABLE systeem ALTER COLUMN aantal_dagen_vooruit_in_te_plannen DECIMAL(6,3) NOT NULL ;
GO
ALTER TABLE systeem ADD CONSTRAINT [DF_systeem_aantal_dagen_vooruit_in_te_plannen1] DEFAULT 0 FOR [aantal_dagen_vooruit_in_te_plannen];
GO
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
August 30, 2010 at 4:13 am
It's working!
Thanks a 10^6
Ray
November 25, 2013 at 8:52 am
Actually if the field is to allow nulls it should be (0) but if it is to not allow nulls it should be ((0))
November 25, 2013 at 9:33 am
Not true. You can wrap expressions in as many brackets as you like, makes no difference.
p.s. 3 year old thread.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply