Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
- `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'Updated At',
- `created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'Created At',
- `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'Updated At',
- mysql> CREATE TABLE mt8
- -> (
- -> billy int,
- -> created_at timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'Created At',
- -> updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Created At'
- -> );
- Query OK, 0 rows affected (0.16 sec)
- mysql>
- mysql>
- mysql> DELIMITER $$
- mysql> create trigger my_ins8_trigger
- -> before insert on mt8
- -> for each row
- -> begin
- -> set new.created_at = current_timestamp;
- -> end $$
- Query OK, 0 rows affected (0.08 sec)
- mysql> DELIMITER ;
- mysql>
- mysql>
- mysql> insert into mt8 values(123, null, null);
- Query OK, 1 row affected (0.08 sec)
- mysql> insert into mt8 values(454, null, null);
- Query OK, 1 row affected (0.05 sec)
- mysql> insert into mt8 values(1676, null, null);
- Query OK, 1 row affected (0.06 sec)
- mysql> insert into mt8 (billy) values(34334);
- Query OK, 1 row affected (0.07 sec)
- mysql> insert into mt8 (billy) values(3506);
- Query OK, 1 row affected (0.05 sec)
- mysql> insert into mt8 (billy) values(3435454);
- Query OK, 1 row affected (0.05 sec)
- mysql> select * from mt8;
- +---------+---------------------+---------------------+
- | billy | created_at | updated_at |
- +---------+---------------------+---------------------+
- | 123 | 2014-06-12 01:53:40 | 2014-06-12 01:53:40 |
- | 454 | 2014-06-12 01:53:40 | 2014-06-12 01:53:40 |
- | 1676 | 2014-06-12 01:53:40 | 2014-06-12 01:53:40 |
- | 34334 | 2014-06-12 01:53:56 | 2014-06-12 01:53:56 |
- | 3506 | 2014-06-12 01:53:56 | 2014-06-12 01:53:56 |
- | 3435454 | 2014-06-12 01:53:56 | 2014-06-12 01:53:56 |
- +---------+---------------------+---------------------+
- 6 rows in set (0.00 sec)
- mysql> update mt8 set billy = 455 where billy = 454;
- Query OK, 1 row affected (0.06 sec)
- Rows matched: 1 Changed: 1 Warnings: 0
- mysql> select * from mt8;
- +---------+---------------------+---------------------+
- | billy | created_at | updated_at |
- +---------+---------------------+---------------------+
- | 123 | 2014-06-12 01:53:40 | 2014-06-12 01:53:40 |
- | 455 | 2014-06-12 01:53:40 | 2014-06-12 01:54:26 |
- | 1676 | 2014-06-12 01:53:40 | 2014-06-12 01:53:40 |
- | 34334 | 2014-06-12 01:53:56 | 2014-06-12 01:53:56 |
- | 3506 | 2014-06-12 01:53:56 | 2014-06-12 01:53:56 |
- | 3435454 | 2014-06-12 01:53:56 | 2014-06-12 01:53:56 |
- +---------+---------------------+---------------------+
- 6 rows in set (0.00 sec)
- mysql>
Add Comment
Please, Sign In to add comment