Main topic: About Begin Trans! Please help !!! The little woman has a stored procedure, which is used to back up the data. The code part is as follows:
Select * Into #test from chat_record
INSERT INTO chat_record_history select * from #test
Delete chat_record where exissrs (select content from #test where chat_record.content = # Test.content)
Put the data in Table Chat_Record first in a temporary table #test. Then place the data in the temporary table #test to the history table chat_record_history, finally delete the same record as the Chat_Record table and the temporary table #test.
Now in Insert Into chat_record_history select * from #test this step, it is not inserted into the historical table, but it deletes it again, the original table data. Now you want to use Begin Trans. How to use it !! ! I have tried it a few times or have a problem. Please help
Reply to: xogirl (xogirl) () Reputation: 97 2003-06-13 11: 54: 02Z score: 0? Up. Strong call.
I hope everyone can help.
TOP
Reply to: caiyunxia () Reputation: 116 2003-06-13 12: 00: 37Z score: 0? Trigger period, better effect
Cretae Trigger TR_NAME_DEL ON Chat_Record
For delete
INSERT INTO RECORD_HISTORY
Select * from deleted
TOP
Reply to: caiyunxia (Monkey) () Reputation: 116 2003-06-13 12: 03: 11Z score: 0? Begin TRAN
Select * Into #test from chat_record
IF @@ error <> o goto quiterror
INSERT INTO chat_record_history select * from #test
IF @@ error <> o goto quiterror
Delete chat_record where exissrs (select content from #test where chat_record.content = # Test.content)
IF @@ error <> o goto quiterror
Commit
Goto Savend
QuitError:
Rollback
Savend:
TOP
Reply to: Crazyfor (Hibernate) () Reputation: 266 2003-06-13 12: 04: 02Z score: 0? Is it data has been deleted,
Try this tool to recover data.
Log Explorer
http://download.heibai.net/download/show.php?id=3125
Unzip password www.heibai.net
The registration machine is a registration code, two
After unlocking the compressed password, there is also a registration machine in the compressed package.
TOP
Reply to: caiyunxia (Monkey) () Reputation: 116 2003-06-13 12: 04: 13Z score: 0? Is there any need to insert a temporary table first, insert the historical table directly into the historical table
TOP
Reply to: happydreame () () Reputation: 204 2003-06-13 12: 08: 02Z score: 0? Declare @select_error int, @insert_error int, @ delete_ERROR INTBEGIN TRAN
Select * Into #test from chat_record
SELECT @select_error = @@ Error
INSERT INTO chat_record_history select * from #test
SELECT @Insert_error = @@ error
Delete chat_record where exissrs (select content from #test where chat_record.content = # Test.content)
SELECT @Delete_ERROR = @@ Error
IF @select_error = 0 and @Ssert_ERROR = 0 and @ delete_error = 0
Begin
Commit TRAN
End
Else
Begin
IF @select_error <> 0
Print "SELECT ERROR"
IF @inser_error <> 0
Print "IsnerT Error"
IF @delte_error <> 0
Print "Delete Error"
Rollback TRAN
End
TOP
Reply to: hjb111 (Bobo, secret to the Internet!) () Reputation: 100 2003-06-13 12: 12: 16Z score: 0? Try:
Begin TranTraction
Select * Into #test from chat_record
INSERT INTO chat_record_history select * from #test
IF @@ Error <> 0
Rollback Transaction
Delete chat_record where exissrs (select content from #test where chat_record.content = # Test.content)
Commit transport
TOP
Reply to: happydreame () () Reputation: 204 2003-06-13 12: 15: 15Z score: 0? Execute Insert Into chat_record_history select * from #test What error is there?