我可以在 mysql 中的 select 语句上启动触发器吗?
每次我 SELECT 时,我都试图在表 X 上运行一个 INSERT 语句,无论如何我只能使用 MySQL 来完成表 Y 中的任何记录吗?
I am trying to run an INSERT statement on table X each time I SELECT any record from table Y is there anyway that I can accomplish that using MySQL only?
触发器之类的东西?
推荐答案
简短的回答是否定的.触发器是用 INSERT、UPDATE 或 DELETE触发的代码>.
Short answer is No. Triggers are triggered with INSERT, UPDATE or DELETE.
可能的解决方案.相当罕见的场景:
Possible solution for this. rather rare scenario:
- 首先写一些存储过程做你想要的
SELECTs表 X. - 然后,限制所有用户只能使用这些存储过程并没有允许他们直接在 table 上使用
SELECTX. - 然后将存储过程更改为还调用一个存储过程执行您想要的操作(
INSERT或其他).
- First, write some stored procedures
that do the
SELECTs you want on table X. - Then, restrict all users to use only
these stored procedures and do not
allow them to directly use
SELECTon table X. - Then alter the stored procedures to
also call a stored procedure that
performs the action you want
(
INSERTor whatever).
相关文章