Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Databases questions

Question

=+b) What do you conclude?

Answered: 1 week ago