1

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

4

2 回答 2

0

去一个而不是触发器ex:在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

`

于 2013-09-21T08:50:57.257 回答
0

不,这是不可能的,我问过 MySQL 的人,他们向我保证 MySQL 目前不支持这个功能,甚至没有计划很快推出,所以不,完全没有希望,这就是答案。

于 2013-10-08T03:26:50.223 回答