From the course: MySQL Advanced Topics (2019)

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Exmple: Timestamps

Exmple: Timestamps

- [Man] Triggers may also be used to create timestamps. In this example, I'll show you how to use triggers to create timestamps and to update a transaction log. Here, I've copied some code from the chapter 5 exercise file. We're using the Scratch database again, creating three tables, customer, sale, and log, widget customer, sale, and log, and you notice that the customer table has this stamp column, the sale column also has a stamp column, and the log table has stamp, event, username, table name, and table ID, and so we'll insert some rows into the customer table, and display it. I'm going to go ahead and execute this, notice we get our little warnings here about dropping tables that don't exist, and that's fine, and here's our widget customer table, it has three rows, Bob, Sally, and Fred, and these other columns are nulls at this point. Those will get filled in as we make sales. So, I'm going to go ahead and create some…

Contents