I have a table which contains 4 fields:
PermID, CN, inAD, and DTS.
I cannot set any of the fields to be unique individually. They do have to be unique by combining PermID and CN.
All the above are acceptable entries, however, I want to make sure that no additional duplicate value combination is inserted: i.e:
another 1016 5997
I'm not sure about the best way to go about doing this, though I figured that a FOR trigger may do the trick, to check upon inserting, and I think should also be INSERT/UPDATE, though I wasn't sure how to write that, and exiting that insert/update statement if it already exists. I've attempted to write it, and I'm pretty sure I did it wrong, but maybe someone out there, can help me with getting what I need. Here's what I have so far: (Please excuse some of the syntax, I know it's wrong).
Also, if there's a better way to do this other than with a trigger, I'm definitely open to suggestions.
CREATE TRIGGER [dbo].[Enrollment_Stop_On_Duplicate] ON [dbo].[Enrollment]
SET NOCOUNT ON;
IF EXISTS(SELECT Enrollment.PermID, Enrollment.CN FROM INSERTED WHERE INSERTED.PermID=Enrollment.PermId and INSERTED.CN=Enrollment.CN);