which will use the NEW and OLD structures to perform an update on all the records in the table…

Consider the following table structure of the table city:

You wish to add a trigger which will use the NEW and OLD structures to perform an update on all the records in the table. The trigger is defined as below,

CREATE TRIGGER Code_Update

BEFORE UPDATE

ON Country

FOR EACH ROW

BEGIN

END;

Consider the following table structure of the table city:

You wish to add a trigger which will use the NEW and OLD structures to perform an update on all the records in the table. The trigger is defined as below,

CREATE TRIGGER Code_Update

BEFORE UPDATE

ON Country

FOR EACH ROW

BEGIN

END;

A.
UPDATE City SET CountryCode = NEW.Code WHERE CountryCode = OLD.Code;

B.
SET City.CountryCode = NEW WHERE City.CountryCode = OLD;

C.
SET City.CountryCode = NEW.Code WHERE City.CountryCode = OLD.Code;

Explanation:
When Country table is updated, it fires the trigger to do a similar update on the City Table.
— Eg if Code in country table is changed IRL > IRE, do the same for CountryCode in City table.
— The statement in the trigger is separate to the event that fired it (no longer concerned with country table)
— Now within trigger statement, issue a statement to update the city table so that it’s CountryCode matches the new Code in Country.
— UPDATE SYNTAX: UPDATE table_name SET column_name = x, column_name = y WHERE…;



Leave a Reply 0

Your email address will not be published. Required fields are marked *