我如何...使用单个存储过程将不得不更新多个表 [英] How do I...use single stored procedure which will have to update multiple tables

查看:136
本文介绍了我如何...使用单个存储过程将不得不更新多个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个存储过程,该过程应该更新多个表...以下是我的插入语句,并且我想对其进行更新

  INSERT   INTO  EmpPayInfo(EmpId,Sno,SalaryAllowance,AccountNumber,Amount, Fix,CompanyCode,IsActive 


  INSERT   INTO  EmpDocument(EmpId,EmpDocument,EmpDocRef,EmpDocPath,EmpDocFile, SNo,CompCode,IsActive 


  INSERT   INTO  EmpDependents(EmpId,Sno,Name,Relation,DOB,护照,备注,CompCode,IsActive 


  INSERT   INTO  EmpInsurance(EmpId,PrdType,PrdProvider,PrdAccNo,PrdRemarks, sno,CompCode,IsActive 


  INSERT   INTO  EmpTraining(EmpId,TrainingDate,TrainingTitle,Remarks,sno, CompCode,IsActive 


  INSERT   INTO  EmpProduct(EmpId,RecDate,Product,Qty,Remarks, sno,CompCode,IsActive 


  INSERT   INTO  EmpNotes(EmpId,Remarks,sno,CompCode,IsActive 

解决方案

这样做.
只需围绕所有插入设置一个事务,这样,如果任何插入由于某种原因而失败,您都可以回滚所有插入.

https://msdn.microsoft.com/en-GB/library/ms188929.aspx [ ^ ]包含示例.

Hi, I want to create a stored procedure that should update multiple tables...following are my insert statements, and I want to make it for update

INSERT INTO EmpPayInfo(EmpId,Sno,SalaryAllowance,AccountNumber,Amount,Fix,CompanyCode,IsActive


INSERT INTO EmpDocument(EmpId,EmpDocument,EmpDocRef,EmpDocPath,EmpDocFile,SNo,CompCode,IsActive


INSERT INTO EmpDependents(EmpId,Sno,Name,Relation,DOB,Passport,Remarks,CompCode,IsActive


INSERT INTO EmpInsurance(EmpId,PrdType,PrdProvider,PrdAccNo,PrdRemarks,sno,CompCode,IsActive


INSERT INTO EmpTraining(EmpId,TrainingDate,TrainingTitle,Remarks,sno,CompCode,IsActive


INSERT INTO EmpProduct(EmpId,RecDate,Product,Qty,Remarks,sno,CompCode,IsActive


INSERT INTO EmpNotes(EmpId,Remarks,sno,CompCode,IsActive

解决方案

So do it.
Just setup a transaction round all the inserts so that if any one fails for whatever reason you can roll back them all.

https://msdn.microsoft.com/en-GB/library/ms188929.aspx[^] includes an example.


这篇关于我如何...使用单个存储过程将不得不更新多个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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