I’m trying the following :
CREATE TRIGGER checkgrade ON
[Homework4part3].[dbo].[Enrollment]
FOR INSERT
AS
IF (NEW.grade > 20)
BEGIN
grade = 3
END
GO
and my table looks like :
Enrollment(course#, QYear, SUID,
units, Grade)
dont know why this error showing :
Msg 102, Level 15, State 1, Procedure checkgrade, Line 7
Incorrect syntax near 'grade'.
There are a few problems.
You need to use the Inserted meta table which covers the newly updated/inserted rows.
You need to perform a proper update as the trigger executes after the update/insert, not in the middle of it.
This might be closer to what’s required:
Note: this is untested, and I’ve guessed as to the primary key columns on your table.