一种形式的多个相互依赖的查询 [英] multiple dinterdependent queries in one form
问题描述
在我的应用程序中,我有一个表单,我必须单击一个按钮就可以完成多个数据库事务.
即
当我点击按钮
查询1>>>将指定值插入到指定表中
查询2.>>选择查询以获取最后输入的名称的主键....即上述插入查询针对其插入的自动编号
查询3>>使用上面的主键recvd将数据插入另一个表中
查询4.使用上方的主键更新另一个表
如果任何查询失败或发生任何异常,则其他查询不起作用
现在我正在尝试使用try catch并在发生异常时删除prevoius插入...
有什么好主意,因为我是sql server 2008的新手.
In my application I had a form where i have to do more than one database transaction within a single button click
ie
When I click button
Query 1 >>>insert designation values to Designation table
query 2. >>select query to get the primary key of last entered designation.... ie .the auto number against which the above insert query inserts
query 3 >> inset data into another table with the primary key recvd from above
query 4 .>> update another table with the primary Key Above
If any of the query fails or any exception occur The others shouldnot work
now I am trying to do it using try catch and deleting prevoius insertions if exception occurs...
Is there any good Ideas as I am new to sql server 2008
推荐答案
您可以使用TransactionScoe.
请查看这篇文章和google,以了解更多信息:
http://simpleverse.wordpress.com/2008/08/05/using -transactionscope-for-handling-transactions/ [
You can use TransactionScoe.
check this article and google for some more:
http://simpleverse.wordpress.com/2008/08/05/using-transactionscope-for-handling-transactions/[^]
Cheers
使用 Sql存储过程 [ Sql事务 [ SQL Server存储过程概述 [ SQL Server事务和错误处理 [
Hi,
Use Sql Stored Procedure[^] to perform all your database operation at a time. In that you need to use Sql Transaction[^] to rollback the transaction if any error occurs.
Refer the links:
Overview of SQL Server Stored Procedure[^]
SQL Server Transactions and Error Handling[^]
All the best.
--Amit
请参阅下面的链接.这可能对您有帮助.
http://msdn.microsoft.com/en-us/library/ms179296%28v = sql.105%29.aspx [ ^ ]
http://www.mssqltips.com/sqlservertutorial/164 /using-try-catch-in-sql-server-stored-procedures/ [
Hi,
See the below link. It might be helpful to you.
http://msdn.microsoft.com/en-us/library/ms179296%28v=sql.105%29.aspx[^]
http://www.mssqltips.com/sqlservertutorial/164/using-try-catch-in-sql-server-stored-procedures/[^]
Thanks,
Viprat
这篇关于一种形式的多个相互依赖的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!