<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當前位置: 首頁 - 科技 - 知識百科 - 正文

        Triggers—MySQL5.6and5.7_MySQL

        來源:懂視網 責編:小采 時間:2020-11-09 19:17:42
        文檔

        Triggers—MySQL5.6and5.7_MySQL

        Triggers—MySQL5.6and5.7_MySQL:MySQL Triggers are changing in 5.7 in a big way. Triggers have been around since 5.0 and have not changed much up to 5.6 but will gain the ability to have multiple triggers on the same event. Previously you had ONE trigger maximum on a BEFO
        推薦度:
        導讀Triggers—MySQL5.6and5.7_MySQL:MySQL Triggers are changing in 5.7 in a big way. Triggers have been around since 5.0 and have not changed much up to 5.6 but will gain the ability to have multiple triggers on the same event. Previously you had ONE trigger maximum on a BEFO

        MySQL Triggers are changing in 5.7 in a big way. Triggers have been around since 5.0 and have not changed much up to 5.6 but will gain the ability to have multiple triggers on the same event. Previously you had ONE trigger maximum on a BEFORE UPDATE, for example, and now you can have multiple triggersandset their order.

        So what is a trigger? Triggers run eitherBEFOREorAFTERanUPDATE,DELETE, orINSERTis performed. You also get access to theOLD.col_nameandNEW.col_namevariables for the previous value and the newer value of the column.

        So how do you use a trigger? Let say you are updating the price of an inventory item in a product database with a simple UPDATE statement. But you also want to track when the price change and the old price.

        The table for products.
        CREATE TABLE products (id INT NOT NULL auto_increment,
        price DECIMAL(5,2) NOT NULL,
        PRIMARY KEY (id));

        The table for price changes on the product table.
        CREATE TABLE products_log (id INT NOT NULL,
        price DECIMAL(5,2) NOT NULL,
        change_date timestamp);

        Now to define a trigger that will log price changes. We do this when a price is updated. Now the use od OLD.price to avoid confusion between the old price or the new price being saved in the log.
        DELIMITER |
        CREATE TRIGGER product_price_logger
        BEFORE UPDATE ON products
        FOR EACH row
        BEGIN
        INSERT INTO products_log (id, price)
        VALUES (id, OLD.PRICE);
        END
        |
        DELIMITER ;

        Add in some data.
        INSERT INTO products (price) VALUES (1.10),(2.24),(.99),(.01),(.34);

        So UPDATE a record.
        UPDATE products SET price='1.11' WHERE ID = 1;

        So did it work? Yes, and no. RunningSELECT * FROM products_log;Provides us with a time stamp of the change and the OLD.price. But I forgot to also record the id!!Challenge: Correct my mistake and compare it to an update I will make in a few days.

        Now 5.7 introduces multiple triggers for the same event. Lets add yet another log this time recording who made the change;

        The ‘who made the change table’.
        CREATE table who_changed (
        id INT NOT NULL,
        who_did_it CHAR(30) NOT NULL,
        when_did_it TIMESTAMP);

        And the second trigger.
        DELIMITER |
        CREATE TRIGGER product_price_whom
        BEFORE UPDATE ON products
        FOR EACH ROW
        FOLLOWS product_price_logger
        BEGIN
        INSERT INTO who_changed (id, who_did_it)
        VALUES (OLD.id, user());
        END
        |
        DELIMITER ;

        SoUPDATE products SET price='19.99' WHERE id=4;is run and we see that both triggers execute. Note thatSHOW TRIGGERS fromschema;does not provide any information on trigger order. But you can find all that asaction_orderinPERFORMANCE_SCHEMA.TRIGGERS

        Being able to order triggers makes it easy to make logical steps when processing data. Can you get into trouble with this? I am certain someone will manage to make a mess with this. But I think most of us will enjoy being able to use this great new functionality.

        聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        Triggers—MySQL5.6and5.7_MySQL

        Triggers—MySQL5.6and5.7_MySQL:MySQL Triggers are changing in 5.7 in a big way. Triggers have been around since 5.0 and have not changed much up to 5.6 but will gain the ability to have multiple triggers on the same event. Previously you had ONE trigger maximum on a BEFO
        推薦度:
        標簽: and mysql mysql5
        • 熱門焦點

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 国产成人毛片亚洲精品| 午夜时刻免费入口| 亚洲女人初试黑人巨高清| 四虎在线成人免费网站| 亚洲小说图区综合在线| 亚洲成AV人网址| 无码av免费网站| 亚洲精品国产综合久久久久紧| 宅男666在线永久免费观看| 精品一区二区三区免费观看 | 亚洲暴爽av人人爽日日碰| 又粗又大又硬又爽的免费视频| 中文字幕版免费电影网站| 中文字幕亚洲精品无码| 在线观看人成网站深夜免费| eeuss影院ss奇兵免费com| 日本久久久久亚洲中字幕| 国产一级淫片免费播放电影| 中文字幕一区二区免费| 欧洲亚洲国产精华液| 亚洲国产老鸭窝一区二区三区| 国产免费观看黄AV片| 最近最好最新2019中文字幕免费| 久久精品国产亚洲AV天海翼| 亚洲国产精品久久久久| 亚洲综合精品网站| 永久免费av无码网站大全| 青青青国产在线观看免费网站 | 久久久久无码精品亚洲日韩| 国产无遮挡色视频免费视频| 99re在线这里只有精品免费| 亚洲阿v天堂在线2017免费| 国产亚洲视频在线| 亚洲精品国产精品| 亚洲色偷偷综合亚洲AV伊人蜜桃| 亚洲图片在线观看| 亚洲国产精品久久久久婷婷软件| 亚洲人成网站18禁止一区| 免费一看一级毛片人| 国产成人免费全部网站| 国产成人免费永久播放视频平台|