创建规则忽略错误的数据;操作正确的数据。
create
rule [规则名称] as on insert to [表名]
where
exists
(select 1 from [表名] where [判断条件])
do instead nothing;
#下面的规则是:插入数据到表system_lock时,id相同的就忽略。
create
rule r_insert_ignore as on insert to system_lock
where
exists
(select 1 from system_lock where id = new.id)
do instead nothing;
后续就可以用正常的语句insert;
文章介绍了如何使用SQL创建规则,当尝试向system_lock表中插入ID已存在的数据时,系统会自动忽略该操作,防止数据冗余。这确保了数据的正确性和完整性。
6443

被折叠的 条评论
为什么被折叠?



