有没有办法实时检测数据库中是否有新记录? [英] Is there a way to realtime detect if there's new record in database?

查看:37
本文介绍了有没有办法实时检测数据库中是否有新记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 MySQL 数据库,并在 C# 和 winforms 中编程.它将通过 LAN 网络在几台 PC 上运行.我想知道是否有一种方法可以检查数据库中是否有变化,而无需每秒进行请求.

I have MySQL database, and program in C# and winforms. It will run on few PC's over the lan network. I want to know if theres a way to check if theres changes in database without doing request each second.

示例:管理员将从数据库中删除记录,在工人电脑上我想自动刷新列表.

Example: Admin will delete record from database, on workers pc I want to refresh list automatically.

推荐答案

不要担心轮询的性能.使用合适的 INDEX,MySQL 可以每秒处理 100 次轮询——无论数据集大小如何.

Don't worry about the performance of polling. With a suitable INDEX, MySQL can handle 100 polls/second -- regardless of dataset size.

让我们看看 SHOW CREATE TABLE 和暂定的 SELECT 来执行轮询";我可能有更多提示.

Let's see SHOW CREATE TABLE and the tentative SELECT to perform the "poll"; I may have further tips.

此外,让我们看看需要触发"工作人员采取行动的管理员查询.当然,管理员可以做一些简单的事情来导致这种情况.对表进行校验和是非常重量级的.

Also, let's see the admin's query that needs to 'trigger' the workers into action. Surely the admin can do something simple to cause that. Doing a checksum of a table is terribly heavyweight.

您应该考虑将管理操作编码在存储过程中,从而将轮询机制与管理操作分开.

You should consider the admin action to be encoded in a Stored Procedure, thereby separating the polling mechanism from the admin action.

JavaScript 可以使用 AJAX 执行 INSERT(或调用存储过程).

JavaScript can use AJAX to do an INSERT (or call a Stored proc).

这句口头禅可能适用:不要排队,去做吧.";即admin/javascript动作可以调用应用程序(PHP/Java/VB/whatever)来实际动作,无需排队.(请提供更多详细信息,以便我们讨论这是否是真正的解决方案.)

This mantra may apply: "Don't queue it, just do it." That is, the admin/javascript action can call an application program (PHP/Java/VB/whatever) to actuall do the action, no need for queuing. (Please provide more details so we can discuss whether this might be the real solution.)

这篇关于有没有办法实时检测数据库中是否有新记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆