Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Clone this wiki locally
Starting with version 5.0, MySQL supports the use of triggers. A trigger is code which is automatically executed in response to certain events. Here is an example of how to use a trigger on a table to insert data into a secondary table.
Objective: When a new member record is added to the members table, add a corresponding record to the member_since table with a current timestamp.
- In phpMyAdmin, select the database that you want to work with.
- Go to the SQL tab at the top of the page.
- In the "Run SQL query/queries on database" form, change the Delimiter to $$. (Located in a small box at the bottom of the form)
- Enter your SQL trigger into the main dialog box on the form. The correct syntax is as follows (per a MySQL employee and it worked for me...)
CREATE TRIGGER membership
AFTER INSERT ON members
FOR EACH ROW
INSERT INTO member_since (member_id,signup_date) values (NEW.member_id,now());
Finally hit "GO" and hopefully you'll have created your new trigger.
for running this command you should have "Super privilege" otherwise you will receive following error :
#1227 - Access denied; you need the SUPER privilege for this operation