Creating a MySQL Trigger

I am trying to create a trigger in MySQL that copies a table row to a new database before and update occurs to use as a revisions system. I am using myphpadmin and the SQL is as follows:

delimiter //
CREATE TRIGGER uom_revision BEFORE UPDATE ON ttb_nhie_unitsofmeasure
	FOR EACH ROW
	BEGIN
	   	INSERT INTO ttb_nhie_unitsofmeasure_rev 
        SELECT FROM ttb_nhie_unitsofmeasure WHERE UnitOfMeasureId = OLD.UnitofMeasureID;
    END;
//
delimiter ;

Open in new window


I am receiving the following error when I try this:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM ttb_nhie_unitsofmeasure WHERE UnitOfMeasureId = OLD.UnitofMeasureId;
    E' at line 5

I am using MySQL version 5.6.17
medievalmanAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

arnoldCommented:
you seem to do a table while you are saying you want to do an update to a separate database.

your error is that you are not specifying the columns that will be inserted, nor are you listing the columns in the select statement.

delimiter //
CREATE TRIGGER uom_revision BEFORE UPDATE ON ttb_nhie_unitsofmeasure
	FOR EACH ROW
	BEGIN
	   	INSERT INTO ttb_nhie_unitsofmeasure_rev (column1, column2,column3)
        SELECT column_column1,column_column2,column_column3 FROM ttb_nhie_unitsofmeasure WHERE UnitOfMeasureId = OLD.UnitofMeasureID;
    END;
//
delimiter ;

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.