November 18, 2015 at 4:41 am
Hi,
I am trying to alter a column with the following syntax but it returns the error - Incorrect syntax near the keyword 'DEFAULT'.
alter table [Projects]
alter column [create_user] [nvarchar](30) NULL DEFAULT SYSTEM_USER
I need to add the DEFAULT SYSTEM_USER with the create_user column. Can someone please advice on this ? Thanks.
November 18, 2015 at 4:58 am
Hi,
Use the below code to add default constraint .
alter table [Projects]
add constraint df_constraint DEFAULT SYSTEM_USER for [create_user]
November 18, 2015 at 4:58 am
alter table projects add constraint DF_Projects_CreateUser_SystemUser DEFAULT SYSTEM_USER FOR create_user
November 18, 2015 at 4:59 am
I don't know why your syntax isn't working, but you could try something like this instead. It's not mandatory to name your constraints, but I recommend you do so in order to avoid getting an ugly-looking system-generated name, and to make it easier to remove the constraint at a later date if you need to do so.
ALTER TABLE Projects ADD CONSTRAINT DF_Projects_CreateUser DEFAULT (SYSTEM_USER) FOR [create_user];
John
November 18, 2015 at 5:00 am
The syntax for adding a default to an existing column is a little weird
ALTER TABLE Projects
ADD DEFAULT SYSTEM_USER FOR create_user
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 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply