|
Home > Archive > MS SQL Server > October 2006 > Unique field pair constraints
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Unique field pair constraints
|
|
| Chris Crowther 2006-10-24, 6:37 pm |
| Hi All,
Is it possible to create an SQL Server constraint that enforces
uniqueness of a field pair combination?
I have a table with three fields, all Int values. One field is merely a
unique ID for the row in the table, the other two fields contain the
UIDs of two rows from two other tables, establishing an association
between them. I need the combination of the two table row UIDs to be
unique, ie I need to prevent duplicate entries in the table.
--
Chris Crowther
Developer
J&M Crowther Ltd
| |
| Paul Ibison 2006-10-24, 6:37 pm |
| Chris,
sure - a script like this will create the unique index for you:
ALTER TABLE xxx ADD CONSTRAINT
IX_Table_A_test_1 UNIQUE NONCLUSTERED
(
xxx,
yyy
)
go
Cheers,
Paul Ibison SQL Server MVP, www.replicationanswers.com .
| |
| Chris Crowther 2006-10-24, 6:37 pm |
| Paul Ibison wrote:
> sure - a script like this will create the unique index for you:
Cheers :)
> Paul Ibison SQL Server MVP, www.replicationanswers.com .
--
Chris Crowther
Developer
J&M Crowther Ltd
|
|
|
|
|