Is there a way for SQL to enforce unique column values, that are not a primary key to another table?
For instance, say I have TblDog
which has the fields:
DogId
-Primary Key
DogTag
-Integer
DogNumber
-varchar
The DogTag
and DogNumber
fields must be unique, but are not linked to any sort of table.
The only way I can think of involves pulling any records that match the DogTag
and pulling any records that match the DogNumber
before creating or editing (excluding the current record being updated.) This is two calls to the database before even creating/editing the record.
My question is: is there a way to set SQL to enforce these values to be unique, without setting them as a key, or in Entity Frameworks
(without excessive calls to the DB)?
I understand that I could group the two calls in one, but I need to be able to inform the user exactly which field has been duplicated (or both).
Edit: The database is SQL Server 2008 R2.