{"id":1907,"date":"2019-04-23T14:57:43","date_gmt":"2019-04-23T06:57:43","guid":{"rendered":"https:\/\/www.yusian.com\/blog\/?p=1907"},"modified":"2020-12-02T14:59:12","modified_gmt":"2020-12-02T06:59:12","slug":"%e8%a7%a6%e5%8f%91%e5%99%a8%e7%9a%84%e7%ae%80%e5%8d%95%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"https:\/\/www.yusian.com\/blog\/database\/2019\/04\/23\/1457431907.html","title":{"rendered":"\u89e6\u53d1\u5668\u7684\u7b80\u5355\u4f7f\u7528"},"content":{"rendered":"<h3>1\u3001\u521b\u5efa\u89e6\u53d1\u5668<\/h3>\n<ul>\n<li>\u4fee\u6539\u754c\u5b9a\u7b26\uff1adelimiter \/\/<\/li>\n<li>\u5b9a\u4e49\u89e6\u53d1\u5668\uff1acreate trigger  xxx after|before  insert|update|delete on xxxx for each row<\/li>\n<li>\u89e6\u53d1\u5668\u6267\u884c\u5185\u5bb9\uff1abegin   xxx    end<\/li>\n<li>\/\/\u6267\u884c<\/li>\n<li>\u8fd8\u539f\u754c\u5b9a\u7b26\uff1adelimiter ;<br \/>\n<!--more--><\/li>\n<\/ul>\n<pre><code class=\"language-sql line-numbers\">mysql&gt; create trigger t_ststis after insert on user for each row\n    -&gt; begin\n    -&gt; update t_statistics set u_count = u_count + 1 where id = 1;\n    -&gt; end \/\/\nQuery OK, 0 rows affected (0.01 sec)\n\n\nmysql&gt; delimiter ;\nmysql&gt; select * from t_statistics;\n+----+---------+\n| id | u_count |\n+----+---------+\n|  1 |       0 |\n+----+---------+\n1 row in set (0.00 sec)\n\n\nmysql&gt; insert into user(user_name, password, email) values('lucy', md5(2), 'lucy@163.com');\nQuery OK, 1 row affected (0.00 sec)\n\n\nmysql&gt; select * from user;\n+----+-----------+-----+----------------------------------+-----------------+---------+---------+-----+---------------------+\n| id | user_name | sex | password                         | email           | address | fee     | age | create_at           |\n+----+-----------+-----+----------------------------------+-----------------+---------+---------+-----+---------------------+\n|  1 | sian      | \u7537  | e10adc3949ba59abbe56e057f20f883e | yusian@163.com  | NULL    | 1200.00 |  32 | 2019-04-23 15:57:29 |\n|  2 | \u4f59\u897f\u5b89    | \u7537  | c4ca4238a0b923820dcc509a6f75849b | yusian@163.com  | NULL    |    1.00 |  33 | 2019-04-21 17:12:55 |\n|  3 | Jack      | \u7537  | c81e728d9d4c2f636f067f89cc14862c | jack@yusian.com | NULL    |    0.00 |  22 | 2019-04-21 20:11:59 |\n|  4 | Rose      | \u5973  | eccbc87e4b5ce2fe28308fd9f2a7baf3 | rose@yusian.com | NULL    |    0.00 |  18 | 2019-04-22 10:46:41 |\n|  5 | Sim       | \u5973  | a87ff679a2f3e71d9181a67b7542122c | sim@yusian.com  | NULL    |    0.00 |  28 | 2019-04-22 10:46:41 |\n|  6 | Tony      | \u7537  | c4ca4238a0b923820dcc509a6f75849b | tony@yusian.com | NULL    |    0.00 |  22 | 2019-04-21 20:41:26 |\n|  7 | lucy      | \u7537  | c81e728d9d4c2f636f067f89cc14862c | lucy@163.com    | NULL    |    0.00 |   0 | 2019-04-23 20:13:01 |\n+----+-----------+-----+----------------------------------+-----------------+---------+---------+-----+---------------------+\n7 rows in set (0.00 sec)\n\n\nmysql&gt; select * from t_statistics;\n+----+---------+\n| id | u_count |\n+----+---------+\n|  1 |       1 |\n+----+---------+\n1 row in set (0.00 sec)\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1\u3001\u521b\u5efa\u89e6\u53d1\u5668 \u4fee\u6539\u754c\u5b9a\u7b26\uff1adelimiter \/\/ \u5b9a\u4e49\u89e6\u53d1\u5668\uff1acreate trigger xxx after|before insert|update|delete on xxxx for each row \u89e6\u53d1\u5668\u6267\u884c\u5185\u5bb9\uff1abegin xxx end \/\/\u6267\u884c \u8fd8\u539f\u754c\u5b9a\u7b26\uff1adelimiter ;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[282],"tags":[327,22,332],"class_list":["post-1907","post","type-post","status-publish","format-standard","hentry","category-database","tag-database","tag-mysql","tag-332"],"_links":{"self":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/1907","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/comments?post=1907"}],"version-history":[{"count":0,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/1907\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/media?parent=1907"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/categories?post=1907"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/tags?post=1907"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}