Question: Reset the Chapter 7 . Students table and Chapter 7 . StudentAudit table back to no data. - - GO CREATE OR ALTER TRIGGER Chapter

Reset the Chapter7.Students table and Chapter7.StudentAudit table back to no data.
-- GO
CREATE OR ALTER TRIGGER Chapter7.trgStudentsInsertCheckGPA
ON Chapter7.Students
INSTEAD OF INSERT
AS
SET NOCOUNT ON;
DECLARE @studentId AS INT;
DECLARE @newGpa AS DECIMAL(3,2);
SELECT @newGpa = StudentGpa FROM INSERTED;
BEGIN
IF(@newGpa >4.0 OR @newGpa <0.0)
BEGIN
RAISERROR('GPA must be between 0 and 4.0',16,1);
ROLLBACK;
END
ELSE
BEGIN
INSERT INTO Chapter7.Students
(StudentName, StudentGpa)
SELECT StudentName, StudentGpa
FROM INSERTED;
SET @studentId = SCOPE_IDENTITY();
INSERT INTO Chapter7.StudentsAudit
(StudentId, StudentName, StudentGpa, AuditAction)
SELECT @studentId, studentName, studentGpa,
'Insert a new student'
FROM inserted;
PRINT('Record inserted');
END;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!