日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql数据库有触发器吗_MySQL数据库之MySQL 触发器实现

發布時間:2024/9/27 数据库 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql数据库有触发器吗_MySQL数据库之MySQL 触发器实现 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

本文主要向大家介紹了MySQL數據庫之MySQL 觸發器實現 ,通過具體的內容向大家展現,希望對大家學習MySQL數據庫有所幫助。

Summary:?in?this?tutorial,?you?will?learn?about?MySQL?triggers?implementation.?In?addition,?we?will?show?you?how?MySQL?stores?trigger?definitions?and?the?limitations?of?triggers?in?MySQL.

Introduction?to?MySQL?triggers

In?MySQL,?a?trigger?is?a?set?of?SQL?statements?that?is?invoked?automatically?when?a?change?is?made?to?the?data?on?the?associated?table.?A?trigger?can?be?defined?to?be?invoked?either?before?or?after?the?data?is?changed?by?INSERT,?UPDATE?or?DELETE?statements.?MySQL?allows?you?to?define?maximum?six?triggers?for?each?table.

BEFORE?INSERT?–?activated?before?data?is?inserted?into?the?table.

AFTER?INSERT-?activated?after?data?is?inserted?into?the?table.

BEFORE?UPDATE?–?activated?before?data?in?the?table?is?updated.

AFTER?UPDATE?-?activated?after?data?in?the?table?is?updated.

BEFORE?DELETE?–?activated?before?data?is?removed?from?the?table.

AFTER?DELETE?–?activated?after?data?is?removed?from?the?table.

When?you?use?a?statement?that?makes?change?to?the?table?but?does?not?use?INSERT,?DELETE?or?UPDATE?statement,?the?trigger?is?not?invoked.?For?example,?the?TRUNCATE?statement?removes?the?whole?data?of?a?table?but?does?not?invoke?the?trigger?associated?with?that?table.

There?are?some?statements?that?use?the?INSERT?statement?behind?the?scenes?such?as?REPLACE?statement?and?LOAD?DATA?statement.?If?you?use?these?statements,?the?corresponding?triggers?associated?with?the?tables?if?available?will?be?invoked.

Triggers?defined?for?a?table?must?have?a?unique?name.?You?can?have?the?same?trigger?name?that?defines?for?different?tables?but?it?is?not?recommended.?In?practice,?the?names?of?triggers?follow?the?following?naming?convention:

(BEFORE?|?AFTER)_tableName_(INSERT|?UPDATE?|?DELETE)

MySQL?Triggers?Storage

MySQL?stores?triggers?in?a?data?directory?e.g.,?/data/classicmodels/?with?the?files?named?tablename.TRG?and?triggername.TRN:

The?tablename.TRG?file?maps?the?trigger?to?the?corresponding?table.

the?triggername.TRN?file?contains?the?trigger?definition.

You?can?back?up?the?MySQL?triggers?by?copying?the?trigger?files?to?the?backup?folder.?You?can?also?backup?the?triggers?using?the?mysqldump?tool.

MySQL?Trigger?Limitations

MySQL?triggers?have?all?features?in?standard?SQL?however?there?are?some?limitations?that?you?should?know?before?using?them?in?your?applications.

MySQL?triggers?cannot:

Use?SHOW,?LOAD?DATA,?LOAD?TABLE,?BACKUP?DATABASE,?RESTORE,?FLUSH?and?RETURN?statements.

Use?statements?that?commit?or?rollback?implicitly?or?explicitly?such?as?COMMIT,?ROLLBACK,?START?TRANSACTION,?LOCK/UNLOCK?TABLES,?ALTER,?CREATE,?DROP,?RENAME,?etc.

Use?prepared?statements?such?as?PREPARE,?EXECUTE,?etc.

Use?dynamic?SQL?statements.

Call?a?stored?procedure?or?stored?function.

In?this?tutorial,?we?have?shown?you?how?triggers?are?implemented?in?MySQL.?We?also?discussed?about?trigger’s?storage?as?well?as?trigger’s?limitations?in?MySQL.

Related?Tutorials

Introduction?to?SQL?Trigger

Create?Trigger?in?MySQL

Managing?Trigger?in?MySQL

本文由職坐標整理并發布,希望對同學們學習MySQL有所幫助,更多內容請關注職坐標數據庫MySQL數據庫頻道!

總結

以上是生活随笔為你收集整理的mysql数据库有触发器吗_MySQL数据库之MySQL 触发器实现的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。