I have a table that contains, for example, two fields that I want to make unique within the database. For example:
create table Subscriber (
ID int not null
I assume that only way to enter data into that table is through SPs, If that's the case you can implement some logic in your insert and update SPs to find if the values you are going to insert / update is already exists in that table or not.
Something like this
create proc spInsert
(
@DataSetId int,
@Email nvarchar(100)
)
as
begin
if exists (select * from tabaleName where DataSetId = @DataSetId and Email = @Email)
select -1 -- Duplicacy flag
else
begin
-- insert logic here
select 1 -- success flag
end
end
GO
create proc spUpdate
(
@ID int,
@DataSetId int,
@Email nvarchar(100)
)
as
begin
if exists
(select * from tabaleName where DataSetId = @DataSetId and Email = @Email and ID <> @ID)
select -1 -- Duplicacy flag
else
begin
-- insert logic here
select 1 -- success flag
end
end
GO