0

I'm trying to create a default constraint here, but the system is generating a weird name for it. If I want to name it df_MY_TABLE_GUID or something, how could I specify that name be used?

ALTER TABLE MY_TABLE ADD MY_GUID uniqueidentifier NOT NULL CONSTRAINT uq_MY_TABLE_GUID UNIQUE (MY_TABLE_GUID) DEFAULT NEWID() WITH VALUES 

1 Answer 1

3

Just specify the constraint name with the full syntax, like the UNIQUE in your example:

ALTER TABLE MY_TABLE ADD MY_GUID UNIQUEIDENTIFIER NOT NULL CONSTRAINT uq_MY_TABLE_GUID UNIQUE (MY_TABLE_GUID) CONSTRAINT df_MY_TABLE_GUID DEFAULT NEWID() WITH VALUES ; 

As a matter of routine, I always prefer and encourage to always name every single constraint I create, for the sake of easy reference latter on.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.