国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數(shù)據(jù)庫 > MySQL > 正文

MySQL 在觸發(fā)器里中斷記錄的插入或更新?

2024-07-24 12:43:55
字體:
供稿:網(wǎng)友
下面是一種實現(xiàn)的方法。思路就是想辦法在觸發(fā)器中利用一個出錯的語句來中斷代碼的執(zhí)行。
mysql> create table t_control(id int primary key);
Query OK, 0 rows affected (0.11 sec)
mysql> insert into t_control values (1);
Query OK, 1 row affected (0.05 sec)
mysql> create table t_bluerosehero(id int primary key,col int);
Query OK, 0 rows affected (0.11 sec)
mysql> delimiter //
mysql> create trigger tr_t_bluerosehero_bi before insert on t_bluerosehero
-> for each row
-> begin
-> if new.col>30 then
-> insert into t_control values (1);
-> end if;
-> end;
-> //
Query OK, 0 rows affected (0.08 sec)
mysql> delimiter ;
mysql>
mysql> insert into t_bluerosehero values (1,20);
Query OK, 1 row affected (0.25 sec)
mysql> insert into t_bluerosehero values (2,40);
ERROR 1062 (23000): Duplicate entry '1' for key 'PRIMARY'
mysql>
mysql> select * from t_bluerosehero;
+----+------+
| id | col |
+----+------+
| 1 | 20 |
+----+------+
1 row in set (0.00 sec)
mysql>
或者
mysql> delimiter //
mysql> create trigger tr_t_bluerosehero_bi before insert on t_bluerosehero
-> for each row
-> begin
-> declare i int;
-> if new.col>30 then
-> insert into xxxx values (1);
-> end if;
-> end;
-> //
Query OK, 0 rows affected (0.06 sec)
mysql> delimiter ;
mysql> delete from t_bluerosehero;
Query OK, 3 rows affected (0.05 sec)
mysql> insert into t_bluerosehero values (1,20);
Query OK, 1 row affected (0.06 sec)
mysql> insert into t_bluerosehero values (2,40);
ERROR 1146 (42S02): Table 'csdn.xxxx' doesn't exist
mysql>

您可能感興趣的文章:

MySQL觸發(fā)器使用詳解mysql觸發(fā)器(Trigger)簡明總結(jié)和使用實例mysql 觸發(fā)器實現(xiàn)兩個表的數(shù)據(jù)同步MYSQL設(shè)置觸發(fā)器權(quán)限問題的解決方法Mysql中的觸發(fā)器簡單介紹及使用案例MySQL筆記之觸發(fā)器的應用如何測試mysql觸發(fā)器和存儲過程用mysql觸發(fā)器自動更新memcache的實現(xiàn)代碼MySQL 5.0觸發(fā)器參考教程MySQL如何創(chuàng)建觸發(fā)器
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 武乡县| 梅州市| 阿拉善左旗| 彰武县| 洛阳市| 福海县| 荥阳市| 达州市| 彰武县| 邛崃市| 大英县| 新闻| 怀仁县| 磐石市| 兴安盟| 吕梁市| 慈溪市| 镇坪县| 湖州市| 新津县| 库尔勒市| 四川省| 金沙县| 资溪县| 手机| 库尔勒市| 望奎县| 嵊州市| 七台河市| 海伦市| 三穗县| 汉川市| 梧州市| 和田市| 正安县| 肃南| 紫金县| 清新县| 韶关市| 名山县| 成都市|