Guest User

Untitled

a guest
Jan 18th, 2018
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
  2. `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'Updated At',
  3.  
  4. `created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'Created At',
  5. `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'Updated At',
  6.  
  7. mysql> CREATE TABLE mt8
  8. -> (
  9. -> billy int,
  10. -> created_at timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'Created At',
  11. -> updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Created At'
  12. -> );
  13. Query OK, 0 rows affected (0.16 sec)
  14.  
  15. mysql>
  16. mysql>
  17. mysql> DELIMITER $$
  18. mysql> create trigger my_ins8_trigger
  19. -> before insert on mt8
  20. -> for each row
  21. -> begin
  22. -> set new.created_at = current_timestamp;
  23. -> end $$
  24. Query OK, 0 rows affected (0.08 sec)
  25.  
  26. mysql> DELIMITER ;
  27. mysql>
  28. mysql>
  29. mysql> insert into mt8 values(123, null, null);
  30. Query OK, 1 row affected (0.08 sec)
  31.  
  32. mysql> insert into mt8 values(454, null, null);
  33. Query OK, 1 row affected (0.05 sec)
  34.  
  35. mysql> insert into mt8 values(1676, null, null);
  36. Query OK, 1 row affected (0.06 sec)
  37.  
  38. mysql> insert into mt8 (billy) values(34334);
  39. Query OK, 1 row affected (0.07 sec)
  40.  
  41. mysql> insert into mt8 (billy) values(3506);
  42. Query OK, 1 row affected (0.05 sec)
  43.  
  44. mysql> insert into mt8 (billy) values(3435454);
  45. Query OK, 1 row affected (0.05 sec)
  46.  
  47. mysql> select * from mt8;
  48. +---------+---------------------+---------------------+
  49. | billy | created_at | updated_at |
  50. +---------+---------------------+---------------------+
  51. | 123 | 2014-06-12 01:53:40 | 2014-06-12 01:53:40 |
  52. | 454 | 2014-06-12 01:53:40 | 2014-06-12 01:53:40 |
  53. | 1676 | 2014-06-12 01:53:40 | 2014-06-12 01:53:40 |
  54. | 34334 | 2014-06-12 01:53:56 | 2014-06-12 01:53:56 |
  55. | 3506 | 2014-06-12 01:53:56 | 2014-06-12 01:53:56 |
  56. | 3435454 | 2014-06-12 01:53:56 | 2014-06-12 01:53:56 |
  57. +---------+---------------------+---------------------+
  58. 6 rows in set (0.00 sec)
  59.  
  60. mysql> update mt8 set billy = 455 where billy = 454;
  61. Query OK, 1 row affected (0.06 sec)
  62. Rows matched: 1 Changed: 1 Warnings: 0
  63.  
  64. mysql> select * from mt8;
  65. +---------+---------------------+---------------------+
  66. | billy | created_at | updated_at |
  67. +---------+---------------------+---------------------+
  68. | 123 | 2014-06-12 01:53:40 | 2014-06-12 01:53:40 |
  69. | 455 | 2014-06-12 01:53:40 | 2014-06-12 01:54:26 |
  70. | 1676 | 2014-06-12 01:53:40 | 2014-06-12 01:53:40 |
  71. | 34334 | 2014-06-12 01:53:56 | 2014-06-12 01:53:56 |
  72. | 3506 | 2014-06-12 01:53:56 | 2014-06-12 01:53:56 |
  73. | 3435454 | 2014-06-12 01:53:56 | 2014-06-12 01:53:56 |
  74. +---------+---------------------+---------------------+
  75. 6 rows in set (0.00 sec)
  76. mysql>
Add Comment
Please, Sign In to add comment