SQLSERVER2005存储过程事务,游标实例

SQLSERVER2005存储过程事务,游标实例,第1张

SQLSERVER2005存储过程事务,游标实例,第2张

存储过程事务
alter proc [dbo]。[Unigo _ community _ deleteprivatemessage]
@ userId int,
@ privateMessageId int
as
BEGIN
IF(@ userId > 0且@ privateMessageId > 0)
BEGIN
BEGIN trans _ MSG
BEGIN
delete from user _ to _ P _ MSG
其中user_id = @userId
和private _ privatecom]
GO
DECLARE @ UserId int
SET @ UserId = 1144
DECLARE @ UserId _ tmp int
DECLARE @ MsgId _ tmp int
DECLARE DELETE _ MESSAGE游标FOR
SELECT user _ to _ p _ msg . user _ id,p _ msg . private _ MESSAGE _ id FROM
[dbo]。[p_msg]
内部联接
[dbo]。user _ to _ p _ msg
ON
[dbo]。[p_msg]。private_message_id =[/ br/] [dbo]。user _ to _ p _ msg . private _ message _ id
其中[dbo]。[p_msg]。user _ id = @ UserId
OPEN DELETE _ MESSAGE
FETCH NEXT FROM DELETE _ MESSAGE
INTO @ UserId _ tmp,@ MsgId _ tmp
WHILE @ @ FETCH _ STATUS = 0
BEGIN
Print '-'+cast(@ UserId _ tmp as varchar)+'-'+cast(@ MsgId _ tmp as
varchar)
EXEC[dbo]。[Unigo _ Community _ DeletePrivateMessage]@ UserId _ tmp,@ MsgId _ tmp
FETCH NEXT FROM DELETE _ MESSAGE INTO @ UserId _ tmp,@ MsgId _ tmp
END
CLOSE DELETE _ MESSAGE
DEALLOCATE DELETE _ MESSAGE
-DELETE两个
DECLARE DELETE_MESSAGE_2游标FOR
SELECT
user _ to _ p _ msg . user _ id,p_msg.private[p_msg]
左外部联接
[dbo]。user _ to _ p _ msg
ON
[dbo]。[p_msg]。private_message_id =
[dbo]。user _ to _ p _ msg . private _ message _ id
其中[dbo]。user _ to _ p _ msg . user _ id = @ UserId
OPEN DELETE _ MESSAGE _ 2
FETCH NEXT FROM DELETE _ MESSAGE _ 2
INTO @ UserId _ tmp,@ MsgId _ tmp
WHILE @ @ FETCH _ STATUS = 0
BEGIN
Print '-'+cast(@ UserId _ tmp as varchar)+'-'+cast(@ MsgId _ tmp as
varchar)[/br[Unigo _ Community _ DeletePrivateMessage]@ UserId _ tmp,@ MsgId _ tmp
FETCH NEXT FROM DELETE _ MESSAGE _ 2 INTO @ UserId _ tmp,@ MsgId _ tmp
END
CLOSE DELETE _ MESSAGE _ 2
DEALLOCATE DELETE _ MESSAGE _ 2
IF @ @ ERROR = 0
BEGIN
-DELETE P _ MSG Info
DELETE P _ MSG其中user _ id = @

位律师回复
DABAN RP主题是一个优秀的主题,极致后台体验,无插件,集成会员系统
白度搜_经验知识百科全书 » SQLSERVER2005存储过程事务,游标实例

0条评论

发表评论

提供最优质的资源集合

立即查看 了解详情