?
Solved

How to add mysql insert trigger

Posted on 2013-11-02
2
Medium Priority
?
565 Views
Last Modified: 2013-11-07
I need to create a a record in tblOrderStatus everytime a record is INSERTED in tblOrders.  I have a bit so far but my big question is how do I insert the tblOrder.id into tblOrderStatus with my trigger?


DELIMITER $$
CREATE TRIGGER after_orderPlaced
AFTER INSERT ON tblOrders
FOR EACH ROW
BEGIN

    INSERT INTO tblStatus
    SET tblLastTime = ADDTIME(Curtime(),'2:00:00'),
            tblLastDate = Curdate()
            tblOrderId = ??????????????
END
0
Comment
Question by:drhamel69
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 43

Accepted Solution

by:
Chris Stanyon earned 2000 total points
ID: 39619740
You use the NEW keyword:

DELIMITER $$
CREATE TRIGGER after_orderPlaced
AFTER INSERT ON tblOrders
FOR EACH ROW BEGIN
   INSERT INTO tblStatus
   SET tblLastTime = ADDTIME(Curtime(),'2:00:00'),
   tblLastDate = CURDATE(),
   tblOrderId = NEW.id;
END$$
DELIMTER;

Open in new window

0
 
LVL 2

Author Closing Comment

by:drhamel69
ID: 39632106
Excellent!
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
Your data is at risk. Probably more today that at any other time in history. There are simply more people with more access to the Web with bad intentions.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question