sql server中的事务和错误处理 [英] Transactions and error handling in sql server

查看:65
本文介绍了sql server中的事务和错误处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,

在我的项目中,两个表一个是Head,另一个是Detail。

主表列是 - HeadId,Name,Address

详细信息表列是 - DetailId(主键),description,rate,HeadId(外键)



有时会发生什么,Record只插入Head表中但没有插入Detail表。我想在存储过程中使用事务一次在两个表中插入记录。还有一件事是我想在Detail表中插入多个记录,在Head表中只插入一条记录。



例如Head - 101,ABC,XYZ

详情 - 1,aaa,10,101

2,bbb,20,101

3,ccc,30,101

请给我这个场景的解决方案

解决方案

阅读以下内容:

SQL Server事务和错误处理 [ ^ ]



了解ADO.NET中的事务和TransactionScope的初学者教程 [< a href =http://www.codeproject.com/Articles/522039/A-Beginners-Tutorial-for-Understanding-Transactiontarget =_ blanktitle =New Window> ^ ]

Hi Friends,
In my project two tables one is Head and another is Detail.
Head table columns are - HeadId,Name,Address
Detail table columns are - DetailId (primary key), description, rate, HeadId(foreign key)

Sometimes what happend,Record is inserted only in Head table but not inserted in Detail table.I want to use transaction in stored procedure for insert record in both tables at a time. and one more thing is I want to insert more than one record in Detail table and in Head table insert only one record.

e.g. Head - 101,ABC,XYZ
Detail - 1,aaa,10,101
2,bbb,20,101
3,ccc,30,101
please give me solution for this scenario

解决方案

Read the following :
SQL Server Transactions and Error Handling[^]

A Beginner's Tutorial for Understanding Transactions and TransactionScope in ADO.NET[^]


这篇关于sql server中的事务和错误处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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