下面是一种实现的方法。思路就是想办法在触发器中利用一个出错的语句来中断代码的执行。 mysql> create table t_control(id int primary key); Query OK, 0 rows affected (0. sec) mysql> insert into t_control values (1); Query OK, 1 row affected (0. sec) mysql> create table t_bluerosehero(id int primary key,col int); Query OK, 0 rows affected (0. sec) mysql> delimiter // mysql> create trigger tr_t_bluerosehero_bi before insert on t_bluerosehero -> for each row -> begin -> if new.col> then -> insert into t_control values (1); -> end if; -> end; -> // Query OK, 0 rows affected (0. sec) mysql> delimiter ; mysql> mysql> insert into t_bluerosehero values (1,); Query OK, 1 row affected (0. sec) mysql> insert into t_bluerosehero values (2,); ERROR (): Duplicate entry '1' for key 'PRIMARY' mysql> mysql> select * from t_bluerosehero; +----+------+ | id | col | +----+------+ | 1 | | +----+------+ 1 row in set (0. 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> then -> insert into xxxx values (1); -> end if; -> end; -> // Query OK, 0 rows affected (0. sec) mysql> delimiter ; mysql> delete from t_bluerosehero; Query OK, 3 rows affected (0. sec) mysql> insert into t_bluerosehero values (1,); Query OK, 1 row affected (0. sec) mysql> insert into t_bluerosehero values (2,); ERROR (S): Table 'csdn.xxxx' doesn't exist mysql>
推荐整理分享MySQL 在触发器里中断记录的插入或更新?(mysql触发器在哪),希望有所帮助,仅作参考,欢迎阅读内容。
文章相关热门搜索词:mysql触发器应用场景,mysql的触发器,mysql触发器应用场景,mysql触发器应用场景,mysql中的触发器,mysql触发器触发条件,mysql触发器触发条件,mysql中的触发器,内容如对您有帮助,希望把文章链接给更多的朋友!
将MySQL数据库移植为PostgreSQL 在北美,人们对于PostgreSQL的热情不断升温。随着PostgreSQL的发展,PostgreSQL8.x已经从技术上超越MySQL5.x,而市场的超越相信只是时间问题。而最终,用户
mysql 操作总结 INSERT和REPLACE 言外之意,就是对数据进行修改。在标准的SQL中有3个语句,它们是INSERT、UPDATE以及DELETE。在MySQL中又多了一个REPLACE语句,因此,本文以MySQL为背景来讨
linux mysql忘记密码的多种解决或Access denied for user 'root'@'localhost' 我的系统是ubuntu6.,最近新装好的mysql在进入mysql工具时,总是有错误提示:#mysql-uroot-pEnterpassword:ERROR():Accessdeniedforuser'root'@'localhost'(usingpassword:NO)