Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

this question is regrading SQL trigger statement as below the registration table

ID: 3708245 • Letter: T

Question

this question is regrading SQL trigger statement as below

the registration table as below

This question is not clear if we create a new record how to included inside a file l need a good solution to understand the consipt

[15] Create a before insert trigger on the Registration table named Registration_Before_Insert. Have the trigger prevent a student from registering for a section that the student is already 5. Page 2 of 3 Unit 03 Instructions Introduction to Enterprise Relational Databases registered for. Write an INSERT statement that successfully creates a registration record then run the same INSERT statement a second time. Your trigger should reject the second INSERT.

Explanation / Answer

The trigger to prevent duplicate record in registration table is given below. The trigger will check if field StudentID, SectionID and Grade matches, the new record will be treated as the duplicate record and will not be inserted to the tables.

Query-

CREATE TRIGGER Registration_Before_Insert ON Registration
BEFORE INSERT
AS

if exists ( select * from Registration t
inner join inserted i on i.StudentID=t.StudentID and i.SectionID=t.SectionID and i.Grade <> t.Grade)
begin
rollback
RAISERROR ('Duplicate Data', 16, 1);
end
go