Incorrect syntax near DEFAULT

  • 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.

  • Hi,

    Use the below code to add default constraint .

    alter table [Projects]

    add constraint df_constraint DEFAULT SYSTEM_USER for [create_user]

  • alter table projects add constraint DF_Projects_CreateUser_SystemUser DEFAULT SYSTEM_USER FOR create_user

  • 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

  • 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

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply