简体   繁体   English

SQL Server对插入行执行操作,该操作会将数据添加到与C#异步的另一个表中

[英]SQL Server invoke action on insert rows that will add data to another table async from C#

I have C# process that insert rows to table in SQL Server 2012. 我有C#进程在SQL Server 2012中向表中插入行。
I want to insert tracking information to another 2 tables as a result with a specific logic. 我想通过特定逻辑将跟踪信息插入到另外2个表中。

I thought about 3 ways to do it: 我考虑了3种方法:

  1. Create stack/collection to will collect the data and will insert by Entity Framework each X seconds/mili. 创建堆栈/集合以收集数据,并每隔X秒/英里由Entity Framework插入一次。

  2. SQL Server trigger that will listen to events on the table and will insert the data to another table. SQL Server触发器将侦听表上的事件并将数据插入到另一个表中。 In case of trigger the action will be synchronized and will slow the operation. 在触发的情况下,动作将被同步并且将降低操作速度。

  3. Async trigger action - Trigger on the table that will send to the service broker queue and will execute it async by procedure. 异步触发操作-在将发送到服务代理队列并按过程异步执行的表上触发。

What is the best way or maybe there is another way? 最好的方法是什么,也许还有另一种方法?

Unless you are confident that the overhead on insert in case 2. is unacceptable, go with it. 除非您确信情况2中插入的开销是不可接受的,否则请选择它。 This way your solution is as good as having two more inserts each time/in the same transaction an insert to the main table is performed. 这样,您的解决方案就像每次有两个以上的插入操作一样好/在同一事务中执行对主表的插入操作。

Thus you will be sure you are not missing inserts due to some unavoidable failure and no need to worry about restarting copy process. 因此,您将确保不会因为某些不可避免的故障而不会丢失插入内容,并且无需担心重新启动复制过程。

I would personally start with this solution first, profile and only then consider other options. 我个人将首先从此解决方案开始,然后介绍配置文件,然后再考虑其他选项。 Actually, I am going to use it in a project of my own. 实际上,我将在自己的项目中使用它。

If you can read a bit about OUTPUT Clause in sql, maybe it can fit best in what you're trying to achieve. 如果您可以阅读一些有关sql中的OUTPUT子句的信息,也许它最适合您想要实现的目标。 Maybe browse this for examples 也许浏览此示例

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

相关问题 从C#中的表单将数据插入SQL Server 2008表 - Insert data into an SQL Server 2008 table from a form in C# 数据从 C# 插入 SQL Server - Data insert into SQL Server from C# 从 C# 中的 .sql 文件插入 SQL Server 多行 - SQL Server multiple rows insert from .sql file in C# C# 数据网格视图,SQL Server:选择多行,然后将具有指定列的选定行插入到 SQL 表中 - C# Data grid view, SQL Server: Select multiple Rows then insert selected rows with specified columns into SQL table 将C#表数据插入SQL Server表 - Insert C# table data into a SQL Server table 在插入选择命令sql c#中从文本框中添加行 - add rows from textbox in insert select command sql c# 使用详细信息表中的外键将数据从C#插入到SQL Server 2005中的主/明细表中 - Insert Data to Master/Detail table in SQL Server 2005 from C# with Foreign key in Detail table 使用c#将MS Access表数据添加到SQL Server表 - Add MS Access table data to SQL Server table with c# 尝试从文本框中将数据放入SQL Server数据库中,并从C#中的另一张表中放入一些数据 - Trying to put data into a SQL Server database from textbox and some data from another table in C# 使用表适配器将数据从C#中的字符串数组插入SQL Server数据库 - using a table adapter to insert data into a SQL Server database from a string array in C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM