Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Newbie, needing help

Author  Topic 

augadgetguy
Starting Member

2 Posts

Posted - 2015-02-26 : 14:55:32
I am a student and working on this question: Extend your CREATE TABLE statement for the Employee Table (problem 2) with a unique constraint for EmpEMail. Use a named constraint clause for the unique constraint.

This is what I have:

Alter table Employee
(EmpEmail VARCHAR(50),
Constraint uq_EmpEmail unique (EmpEmail))

And I keep getting this error message:

Msg 102, Level 15, State 1, Line 2
Incorrect syntax near '('.

Can someone please help me with what I am doing wrong? Thank you in advance

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2015-02-26 : 15:14:42
You need to use ALTER TABLE ADD CONSTRAINT syntax: https://msdn.microsoft.com/en-us/library/ms190273.aspx

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

augadgetguy
Starting Member

2 Posts

Posted - 2015-02-26 : 15:34:47
As I mentioned, I am very new to this and the instructions that you attached are a bit confusing to me at the moment. Can someone please easily explain to me what I need to do?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2015-02-26 : 15:38:41
Here's an example I grabbed from a quick google search using "ALTER TABLE ADD CONSTRAINT":

ALTER TABLE table_name
ADD CONSTRAINT MyUniqueConstraint UNIQUE(column1, column2);

I mention the google search because I don't have most syntax memorized and always have to look it up. Get comfortable searching for examples as you're going to need to do this plenty of times. I lookup syntax numerous times per week.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -