我一个极度简单的问题,问题虽然简单,但又极别重要。所以放高分!

ZXYSOSO 2006-07-27 03:33:05
Update P
Set P.fldComPanys=T.fldComPanys,
P.fldDeliveryPlaceS=T.fldDeliveryPlaceS,
P.fldWarehouseS=T.fldWarehouseS
From svr_Master_Po P, #Tmp_Po T
Where P.fldPoNos=T.fldPoNos
And P.fldVendorCodes=T.fldVendorCodes

Select @PayMent=isnull(fldpaymentdays,'')+isnull(fldpaymentterms,'')+isnull(fldpaymentchannels,'')+isnull(fldpaymentremarks,'')
From svr_Master_Vendor
Where fldVendorCodeS=@Vendor

Update P
Set P.fldComPanys=T.fldComPanys,
P.fldDeliveryPlaceS=T.fldDeliveryPlaceS,
P.fldWarehouseS=T.fldWarehouseS
From svr_PR_POQty P, #Tmp_Po T
Where P.fldPoNos=T.fldPoNos

假如要更新上面两个表,那事务应该怎样加呢?

如果这样可以吗?
SET XACT_ABORT ON
Begin Tran
......
......
Commit Tran
这样做,会不会锁住表?

如果要用Rollback Tran,应该怎样用呢?


...全文
262 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
cywarson 2006-07-28
  • 打赏
  • 举报
回复
试一试..
xyxfly 2006-07-27
  • 打赏
  • 举报
回复
:)
yjlhch 2006-07-27
  • 打赏
  • 举报
回复
学习
zjcxc 元老 2006-07-27
  • 打赏
  • 举报
回复
SET XACT_ABORT ON
Begin Tran
......
......
Commit Tran
这样做,会不会锁住表?

如果要用Rollback Tran,应该怎样用呢?

------------------------------------------

rollback tran在出错时自动进行. 至于锁表, 事务中的update在事务提交或者回滚前肯定是要锁表的
WangZWang 2006-07-27
  • 打赏
  • 举报
回复
如果只有这条语句执行,不会锁表,
SET XACT_ABORT ON 打开后,遇到错误
会自动进行回滚Rollback Tran.
ZXYSOSO 2006-07-27
  • 打赏
  • 举报
回复
这样做可不可以?会锁表吗?
SET XACT_ABORT ON
Begin Tran
......
......
Commit Tran
wwh999 2006-07-27
  • 打赏
  • 举报
回复
顶楼上的贴...真是快,不写了.
WangZWang 2006-07-27
  • 打赏
  • 举报
回复
如:
Begin Tran
Update P
Set P.fldComPanys=T.fldComPanys,
P.fldDeliveryPlaceS=T.fldDeliveryPlaceS,
P.fldWarehouseS=T.fldWarehouseS
From svr_Master_Po P, #Tmp_Po T
Where P.fldPoNos=T.fldPoNos
And P.fldVendorCodes=T.fldVendorCodes
if @@error<>0 goto error

Select @PayMent=isnull(fldpaymentdays,'')+isnull(fldpaymentterms,'')+
isnull(fldpaymentchannels,'')+isnull(fldpaymentremarks,'')
From svr_Master_Vendor
Where fldVendorCodeS=@Vendor

Update P
Set P.fldComPanys=T.fldComPanys,
P.fldDeliveryPlaceS=T.fldDeliveryPlaceS,
P.fldWarehouseS=T.fldWarehouseS
From svr_PR_POQty P, #Tmp_Po T
Where P.fldPoNos=T.fldPoNos
if @@error<>0 goto error

Commit Tran
Return

error:
Rollback Tran
Print 'Error!'
go

34,589

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧