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
 Unique Column Data

Author  Topic 

larrythek
Starting Member

7 Posts

Posted - 2008-01-22 : 10:29:09
Absolute SQL Beginner here

I am using SQL Server 2005 Express Edition in conjunction with asp.net 2.0

Is there any way to guarantee when INSERTing data, that all values in a given column (which is of a char data type) are unique? Or do I have to do this programatically at the asp layer?

Thanks in advance

Larry

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-01-22 : 10:31:06
You can add a UNIQUE INDEX or a UNIQUE CONSTRAINT for the column in mind.
If a duplicate value is inserted, the DB will generate an error for you.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-01-22 : 10:31:25
You can place unique constraint on the desired column at table level.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

larrythek
Starting Member

7 Posts

Posted - 2008-01-22 : 10:36:40
Thanks Peso for your reply...but I'm still confused

Can I do this with a Column property when I establish the table definition? I don't see anything there that applies.

Or must this constrain be applied when an INSERT is executed. If so, can you show me the syntax?

Thanks

Larry
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-01-22 : 10:40:04
CREATE UNIQUE INDEX IX_BlaBlaBla ON MyTable (MyColumn)



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -