If I have this statement:
ALTER TABLE RecipeBox.Recipe ADD CONSTRAINT AKRecipeBox_Recipe_Name
UNIQUE NONCLUSTERED (Name)
How do I add another constraint to this statement? Is this even possible?
Thanks
Using SQL SERVER 2008 Developer Edition
If I have this statement:
ALTER TABLE RecipeBox.Recipe ADD CONSTRAINT AKRecipeBox_Recipe_Name
UNIQUE NONCLUSTERED (Name)
How do I add another constraint to this statement? Is this even possible?
Thanks
Using SQL SERVER 2008 Developer Edition
Add a comma, then add the new constraint (without add keyword) like this:
ALTER TABLE RecipeBox.Recipe ADD CONSTRAINT AKRecipeBox_Recipe_Name
UNIQUE NONCLUSTERED (Name),
CONSTRAINT your_constraint UNIQUE NONCLUSTERED (yourColumn) -- (or whatever type of constraint you're looking for)
Change the layout slightly and read ALTER TABLE
ALTER TABLE RecipeBox.Recipe WITH CHECK ADD
CONSTRAINT AKRecipeBox_Recipe_Name UNIQUE NONCLUSTERED (Name),
CONSTRAINT FK_foo_bar FOREIGN KEY ...,
CONSTRAINT CK_foo_bar CHECK (...)
Edit: use WITH CHECK to ensure the constraints are valid...
Since the title of this question does not refer to SQL Server, I opened it to find a solution for Oracle DB which is different from accepted answer. So I will leave it below in case someone else follows my steps.
For Oracle DB:
ALTER TABLE RecipeBox.Recipe
ADD (CONSTRAINT your_first_constraint, CONSTRAINT your_second_constraint);