mysql - SQL - 触发器和意外事件

标签 mysql sql

if (exists (select * from sysobjects where xtype='tr' and name='trig'))
    drop trigger trig1


go
create trigger trig1 on participari
after insert,update,delete
as
begin
    if (exists (select * from deleted))
        rollback

    if (exists (select * from inserted,proiecte
where inserted.idpr = proiecte.idpr
and deadline<dela union 
select * from inserted,proiecte
where inserted.idpr = proiecte.idpr and inserted.panala>proiecte.deadline))
end

我为其中一个表创建的触发器。基本上它涉及2个表。一个是“proiecte”(项目),另一个是“participari”(参与)。 projects 表包含项目 ID、项目名称和截止日期。参与有项目 ID(外国)、参与者姓名、从和到(时间间隔,每个标记有 2 个不同的列)。它最后给了我一个错误,一个语法错误,我无法理解它。谁能帮帮我?

最佳答案

您似乎缺少对第二个 if 子句的任何操作。

IF(
  EXISTS(
    SELECT * FROM ...
    UNION
    SELECT * FROM ...
  )
)
-- do what?

关于mysql - SQL - 触发器和意外事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16995193/

相关文章:

php - codeigniter 中的 XSS 过滤不能防止 SQL 注入(inject)吗?

sql - WHERE ... IN 条件和子查询中的多列

php - 如何像mysql结构一样在redis中存储数据或者按值搜索redis数据

mysql - CakePHP 查询中 strtotime() 的替代方案

android - 从 xml(remote) Android 将数据导入到 sqlite

php - 在 php 页面上显示可编辑的电子表格

sql - 使用 sqlite 在列中查找最常见的单词?

mysql - 在 MySQL Case 运算符的结果上添加一些文本

java - 方法返回对象列表的 NULL 值

sql - 用选择概率优化 T-SQL 查询