Question
Create trigger CHECK_MEMBERSHIP_UPDATE ON MEMBERSHIP BEFORE UPDATE on MEMBERSHIP for each row DECLARE MembershipID varchar(20); FirstName varchar(20); LastName varchar(20); MembershipLevel varchar(20); MemberExpDate
Create trigger CHECK_MEMBERSHIP_UPDATE ON MEMBERSHIP
BEFORE UPDATE on MEMBERSHIP
for each row
DECLARE
MembershipID varchar(20);
FirstName varchar(20);
LastName varchar(20);
MembershipLevel varchar(20);
MemberExpDate date;
BEGIN
-- Members who have a non expired membership
IF MemberExpDate > CURDATE() THEN
UPDATE MEMBERSHIP
IF MembershipLevel = 'Platinum' then
SET MembershipLevel = 'Gold'
END IF
IF MembershipLevel = 'Gold' then
SET MembershipLevel = 'Silver'
END IF
IF MembershipLevel = 'Silver' then
SET MembershipLevel = 'Expired' AND MemberExpDate = 'NULL'
END IF
END IF;
-- membership expired
IF MemberExpDate <= CURDATE() THEN
SIGNAL SQLSTATE '1066'
SET MESSAGE_TEXT = 'Membership cannot be updated for user as membership has already expired. Please renew membership to change membership levels';
END IF;
-- if trying to change to the same level
IF (Old.MembershipLevel = New.MembershipLevel) THEN
SIGNAL SQLSTATE '1055'
SET MESSAGE_TEXT = 'Membership cannot be changed to a membership of the same level';
END IF ;
END;
//
DELIMITER
Not sure why I get an error in line 1? I believe I did the syntax correctly, could someone help? Here is the question below:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started