本文介绍了如何使用触发器将两个表组合在另一个表中。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 嗨.... 在我的数据库两个表中 1)InvoiceDetails 2)AppliedTax in invoiceDetails三个属性Invoice_ID,InvoiceDetails_ID ,TaxName和In AppliedTax三个属性AppliedID,AppliedTaxName,Grand Total。 这两个表属性在单个表(InvoiceMD)中结合两个触发器的使用方式。 当单表可行时但问题是插入数据时所有数据再次重复。 ALTER 触发器 [dbo]。[trg_InvoiceMD] 开启 [dbo]。[InvoiceDetails] Insert As 开始 声明 @ InvoiceDetails_ID int ; 声明 @ Invoice_ID int ; 声明 @ TaxName nvarchar ( 100 ); 插入 进入 InvoiceMD 选择 InvoiceDetails_ID,Invoice_ID,TaxName from InvoiceDetails - 其中Invoicedetails_ID = @ InvoiceDetails_ID end 解决方案 尝试以下触发器。它只会插入新添加的记录。如果你想组合多个表,那么使用连接相应地修改触发器 - ALTER 触发器 [dbo]。[trg_InvoiceMD] On [dbo]。[InvoiceDetails] 插入 As 开始 声明 @ InvoiceDetails_ID int ; 声明 @ Invoice_ID int ; 声明 @ TaxName nvarchar ( 100 ); 插入 进入 InvoiceMD 选择 InvoiceDetails_ID,Invoice_ID,TaxName 来自 INSERTED - 其中Invoicedetails_ID = @ InvoiceDetails_ID end Hi.... In my databse two table 1)InvoiceDetails 2)AppliedTaxin invoiceDetails Three attribute Invoice_ID,InvoiceDetails_ID,TaxName and In AppliedTax Three Attribute AppliedID,AppliedTaxName,Grand Total.these two table Attribute In single table(InvoiceMD) combine how two trigger use. when single table is possible But probl is when data inserted all data are repeated again again.ALTER trigger [dbo].[trg_InvoiceMD]On [dbo].[InvoiceDetails]After InsertAsBegindeclare @InvoiceDetails_ID int;declare @Invoice_ID int;declare @TaxName nvarchar(100);insert into InvoiceMD Select InvoiceDetails_ID,Invoice_ID,TaxNamefrom InvoiceDetails --where Invoicedetails_ID=@InvoiceDetails_IDend 解决方案 Try the below trigger. It will insert only newly added records. If you want to combine multiple tables then modify the trigger accordingly using joins - ALTER trigger [dbo].[trg_InvoiceMD]On [dbo].[InvoiceDetails]After InsertAsBegindeclare @InvoiceDetails_ID int;declare @Invoice_ID int;declare @TaxName nvarchar(100);insert into InvoiceMD Select InvoiceDetails_ID,Invoice_ID,TaxNamefrom INSERTED--where Invoicedetails_ID=@InvoiceDetails_IDend 这篇关于如何使用触发器将两个表组合在另一个表中。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-29 21:41