两个用户同时打开delphi开发的应用程序修改一个表(用的是TQuery控件,不是Table,缓存更新方式),在第一个用户修改提交后,怎么保证第二个用户提交时发现这条记录已被其它用户修改(包括不同的字段).
(MS SQL SERVER 修改的触发器是after触发,不像Oracle一样有Before?如何是好?)
...全文
8216打赏收藏
关于并发修改的头痛问题
两个用户同时打开delphi开发的应用程序修改一个表(用的是TQuery控件,不是Table,缓存更新方式),在第一个用户修改提交后,怎么保证第二个用户提交时发现这条记录已被其它用户修改(包括不同的字段). (MS SQL SERVER 修改的触发器是after触发,不像Oracle一样有Before?如何是好?)
if you use SQL SERVER 2K,you can use instead of trigger.
SQL Server 2000 allows you create a second kind of trigger, called an instead-of trigger. An instead-of trigger, rather than the data modification operation that fires the triggers, specifies the action to take. Instead-of triggers are different from after triggers in several ways:
You can have only one instead-of trigger for each action (INSERT, UPDATE, and DELETE).
You cannot combine instead-of triggers and foreign keys that have been defined with CASCADE on a table. For example, if Table2 has a FOREIGN KEY constraint that references Table1 and specifies CASCADE as the response to DELETE operations, you will get an error message if you try to create an instead-of trigger for DELETE on Table2. However, you can have instead-of triggers for INSERT or UPDATE. Similarly, if you already have an instead-of trigger on Table2, you cannot alter the table to add a foreign key constraint with the CASCADE action for the same data modification operation.
Instead-of triggers can never be recursive, regardless of the setting of the recursive triggers database option. For example, if an instead-of trigger is executed for INSERT into Table1 and the trigger does an INSERT into Table1, the instead-of trigger is not processed. Instead, the INSERT is processed as if there were no instead-of trigger for INSERT, and any constraints and after triggers will take effect.