help needed with trigger
hello please i need help with this trigger, i have a trigger that stops a record in a table from being duplicated. each time i insert a record, it fires and raises an error not minding if the condition in the trigger was true or false.
pls find trigger below
from this trigger, i am trying to prevent the following record below from repeating twice. (i am avoiding duplicate records)
alter trigger TRG_CHECK_PROGRAMME_COURSE_DUPLICATE
declare @ProgrammeId int,
if exists( select ProgrammeCourseId
RAISERROR ('This Course SetUp Already Exist, Add New Operation Aborted', 16, 1)
please what am i doing wrong?
for starters, you're re-inventing the wheel, trying to do with a trigger something that the database can do for you automatically with a unique constraint
Originally Posted by nellyihu
ok, pls how do i go about it using constraints?
did you read the page i linked to?