From the course: MySQL Advanced Topics
Unlock this course with a free trial
Join today to access over 24,300 courses taught by industry experts.
Example: Timestamps - MySQL Tutorial
From the course: MySQL Advanced Topics
Example: Timestamps
- [Bill] Hi, I'm Bill Wyman. Triggers may be used to create timestamps. In this example, I'll show you how to use a trigger to create timestamps and to update a transaction log, copy this block of code from the chapter five exercise file. We'll start by using the scratch database, and we're going to create three tables, a customer table, a sale table, and a log table. And we'll insert some customers and we'll go ahead and select from the customer table. We'll go ahead and execute this. You can see that we have columns for ID, name, last order ID, and a timestamp for that order. And we're going to fill those columns in from some triggers. Well, first of course we drop trigger if exists for these two new triggers. And then you'll notice we set the delimiter and then we create two triggers before we reset the delimiter. That's fine, we can do that because we're using this delimiter, we're just sending to statements to the server. So we have one trigger that's a before insert on. So when…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.