简体   繁体   English

使用MySQL的select语句是否可能触发?

[英]Is it possible a trigger on a select statement with MySQL?

I know that triggers can be used on insert, update and delete, but what about a trigger (or sort of) on a select statement. 我知道触发器可以用于插入,更新和删除,但是select语句上的触发器(或某种触发器)呢? I want to use a trigger to insert data on a table B when it is selected an existent record on a table A, it could be possible?. 当选择表A上的现有记录时,我想使用触发器在表B上插入数据,这可能吗?

Thanks in advance. 提前致谢。

您应该设计应用程序,以便仅通过某些方法可以进行数据库访问,并在这些方法中添加所需的监视。

It is not possible in the database itself. 在数据库本身中是不可能的。

However there are monitoring/instrumentation products for databases (eg for Sybase - not sure about MySQL) which track every query executed by the server, and can do anything based on that - usually store the query log into a data warehouse for later analysis, but they can just as well insert a record into table B for you, I would guess. 但是,有一些用于数据库的监视/仪器产品(例如,对于Sybase-不确定MySQL),该产品可以跟踪服务器执行的每个查询,并且可以基于此执行任何操作-通常将查询日志存储到数据仓库中以便以后进行分析,但是我猜他们也可以为您向表B中插入一条记录。

Not exactly a trigger, but you can: 不完全是触发器,但是您可以:

CREATE FUNCTION myFunc(...) BEGIN INSERT INTO myTable VALUES(...) END;

And then 接着

SELECT myFunc(...), ... FROM otherTable WHERE id = 1;

Not an elegant solution, though. 但是,这不是一个优雅的解决方案。

You can write an application which will be monitoring the query log and doing something when a select occurs. 您可以编写一个应用程序,该应用程序将监视查询日志并在发生选择时执行某些操作。 A pretty crude way to solve the problem though... 解决问题的一种很粗略的方法...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM