是否可以创建在任何表中的任何插入上触发的触发器?

时间:2013-09-20 17:36:25

标签: mysql sql triggers

我想创建一个MySQL触发器,它在任何表中的任何行插入之前运行。那可能吗?另一种方法是在为每个表插入之前创建一个触发器,但这还不够好:它很乱并且它不处理新表,所以我肯定想编写一个MySQL触发器,它会在任何插入任何插入时触发行。那可能吗?如果是这样,怎么样? (我在文档中找不到任何引用)

2 个答案:

答案 0 :(得分:0)

去寻找而不是触发器 例如:在sql server中

create trigger name
on table_name
instead of insert 
as
begin
if exists9select count(*) from inserted as i
join table_name as t
on i.id-t.id
group by i.id
having count(*) >1)
begin
raiseerror "duplicate category names npt allowsed"
end
else
insert into table_name (col1,col2)
select col1,col2 from inserted

`create trigger name
on table_name
instead of insert 
as
begin
if exists9select count(*) from inserted as i
join table_name as t
on i.id-t.id
group by i.id
having count(*) >1)
begin
raise error "duplicate category names not allowed"
end
else
insert into table_name (col1,col2)
select col1,col2 from inserted
end
go

`

答案 1 :(得分:0)

不,这是不可能的,我已经问过来自MySQL的人,他们向我保证MySQL目前不支持这个功能,甚至没有计划在任何时候,所以没有,没有希望,这就是答案