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.
| Author |
Topic |
|
johns
Starting Member
24 Posts |
Posted - 2003-06-27 : 11:18:48
|
| I have an alphanumeric field that contains product codes and has to be a unique value. I have always used the IF EXISTS operator to check for matching records. I am wondering if there is another, faster way to perform this operation on a large table of records in SQL Server 2000?Thanks,John S. |
|
|
setbasedisthetruepath
Used SQL Salesman
992 Posts |
Posted - 2003-06-27 : 11:38:02
|
If it has to be unique then you should enforce it through a unique index. As far as checking to see if an insert would violate uniqueness, exists() is a good way to go, as in:insert {table} {column list} select {column list} from {table} p where not exists ( select 1 from {table} where {key} = {p.key})Jonathan{0} |
 |
|
|
Amethystium
Aged Yak Warrior
701 Posts |
Posted - 2003-06-27 : 11:38:39
|
Just stick a unique constraint on the column in question.  |
 |
|
|
|
|
|