Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting up Unique Constraint on a Column.

Status
Not open for further replies.

mateobus

Programmer
Aug 20, 2007
28
US
Hello, I have a table called MyTable, and a Column in that table called UniqueColumn. I was wondering, how, in Enterprise Manager do I enforce a unique constraint on that column?
 
In Enterprise Manager, do the following:

* Navigate to the table.
* Right-click on that table and select "Design Table".
* Right-click on the column you're interested in and select "Check Constraints".
* Click the "New" button and go from there.

Hope it helps! :)
 
alter table Blah add constraint UQ_Blah_ColumnName UNIQUE ON ColumnName


from memory... might need slight alteration.

[COLOR=black #d0d0d0]My alarm clock causes time travel. When I hit snooze, no apparent time passes before the alarm sounds again, but the universe has in fact moved forward through time by ten minutes![/color]
 
he is asking for EM not QA!
I do agree that it is easier in QA but here is the EM version
right click on the table-->design table-->manage indexes/keys from the menu(2nd from right)
Click new, select Create UNIQUE and also select Constraint
close and save

Denis The SQL Menace
--------------------
SQL Server Code,Tips and Tricks, Performance Tuning
SQLBlog.com, Google Interview Questions
 
I didnt realize that there was a way to do it in QA. Nonetheless, thanks for all the help guys.
 
>>I didnt realize that there was a way to do it in QA. Nonetheless, thanks for all the help guys.


???

Whatever is done in EM can be done in QA and much more, fire up profiler do you stuff in EM and you can see all the stuff that EM does behind the scenes

Denis The SQL Menace
--------------------
SQL Server Code,Tips and Tricks, Performance Tuning
SQLBlog.com, Google Interview Questions
 
Denis, I understand that, its just easier to alter the table using the gui, than sql syntax which is tough to remember...
 
>>its just easier to alter the table using the gui, than sql syntax which is tough to remember...

It is also easier not to get the job that way, when I last asked a person how to create a primary key, she answered I click on the yellow key in EM

A lot of jobs require that you submit changes (including rollback/backout) with SQL scripts. In a lot of jobs you will not have access to a production DB, you will be required to submit the script and the 800 pound gorilla will do the hard work of pressing F5, if there is an error he will run the rollback script (if needed)

I would urge you to studt T-SQL, you will know better what goes on behind the scenes and in the end you will see that it is actually faster. And of course it will look good at a job interview ;-)

Denis The SQL Menace
--------------------
SQL Server Code,Tips and Tricks, Performance Tuning
SQLBlog.com, Google Interview Questions
 
he is asking for EM not QA!
Right. Always give the person ONLY what he asks for and never offer more. Gotcha.

[COLOR=black #d0d0d0]My alarm clock causes time travel. When I hit snooze, no apparent time passes before the alarm sounds again, but the universe has in fact moved forward through time by ten minutes![/color]
 
ESquared, I appreciate knowing how to do it on both. Thanks.
 
by the way, correct syntax is not "ON ColumnName." It is:

Code:
alter table Blah add constraint UQ_Blah_ColumnName UNIQUE (ColumnName)
sometimes in DDL it's "ON item" and sometimes it's "(item)" and sometimes it's "FOR item" and the ones I do less often I occasionally have to twiddle with...

Note that UQ_Blah_ColumnName is just the constraint name I chose. You can use anything you want. Choose something logical and be consistent. When you get a constraint violation it's nice for the name to tell you all you need to know without having to look up what the heck it is.

[COLOR=black #d0d0d0]My alarm clock causes time travel. When I hit snooze, no apparent time passes before the alarm sounds again, but the universe has in fact moved forward through time by ten minutes![/color]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top