English 中文(简体)
ql服务器关于更新表格的理论
原标题:sql server theory about updating a table

我有一流网,用户可以更新数据库中的表格。 我想知道这样做的适当方法。 如你在以下图像中看到的那样,红沙区是我通常掌握的数据,即:我需要更新<>>>>not。

enter image description here

Here are the steps that I need to take:

  1. Don t update data if it exists
  2. Delete data that is not in the user update
  3. Add data from the user update that is not already in the table

我也需要审计这一表格,因此我将对此有所启发。 我想从理论上知道,在表格上进行这种更新的最佳方式是什么?

thank you to Aaron who introduced the concept of merge.

下表数据显示:

foreignkey  model  primarykey
1            AA       1
1            AA1      2
1            AA3      3
23           B        4
22           C        5

用户将增加这方面的数据:

foreignkey  model  primarykey
1            A1       1
1            AA1      2
1            AA3      3
22           C        5

如你所知,第一行已经更新,第二行至最后一行完全删除。 您能否帮助我再次发言?

最佳回答

是的,它有可能,它被称为一种合并。 见“服务器”文件。 MERGE 声明

If you don t want to perform any updates if the data already exists, then just don t add a WHEN MATCHED clause. USE WHEN NOT MATCHED BY SOURCE and WHEN NOT MATCHED BY TARGET to insert/delete the missing/removed rows.

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签