From the course: Advanced MySQL Database Administration

Unlock this course with a free trial

Join today to access over 24,900 courses taught by industry experts.

Solution: Triggers

Solution: Triggers

- [Instructor] All right, this is the solution video for your assignment on creating an automated orders trigger. So as a reminder, building on the orders table that we just created previously, Sally would like you to create some form of automation so that every time an order_items record is added to the database, the orders table is automatically updated. This is getting into some pretty cool and heavy DBA stuff. Don't worry about this. Sometimes people can be intimidated by the automation stuff. It's really not that bad and I'll walk you through it, step by step. So we've got this REPLACE INTO statement here. This will look very familiar. Previously you worked with an INSERT INTO statement and it had the same code logic here to populate orders from order_items. The main difference with REPLACE INTO versus INSERT INTO is if any of the records that you're trying to insert have the same primary key or unique index value, then instead of creating an additional row, it's going to update…

Contents