Solved

Transaction Processing - Using SQL Server 2000

Posted on 2008-06-12
7
210 Views
Last Modified: 2012-06-27
This is a follow-up question to http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/Q_23480417.html

I have tried to wrap everything into a transaction, however, when it gets to the point of
  SELECT * INTO table1 FROM (SELCT * FROM table1 UNION ALL SELECT * FROM table3) A
which actually should read:
  SELECT * INTO table1 FROM (SELECT * FROM table2 UNION ALL SELECT * FROM table3) A

I get an error:
  Invalid object name 'dbo.table2'.

table2 is the original table1, which was renamed at the start of the transaction. Any ideas how I can fix this?
 
0
Comment
Question by:dbbishop
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 19

Accepted Solution

by:
elimesika earned 250 total points
ID: 21774234
HI

try the following , this does the same without using sp_rename , I don't think that sp_rename works inside a transaction, I think that it will update the system tables only after the commit

DROP TABLE table2
SELECT * INTO table2 FROM (SELECT * FROM table1)
DROP TABLE table1
TRUNCATE TABLE 'table3'
BULK INSERT table3 FROM ...
DELETE table3 ...
UPDATE table3 ...
SELECT * INTO table1 FROM (SELECT * FROM table2 UNION ALL SELECT * FROM table3) A

Open in new window

0
 
LVL 15

Author Comment

by:dbbishop
ID: 21776066
I may have to go to that if sp_rename will not work inside the transaction. That is what the original code had, but I was hoping to do away with it (while doing everything inside a transaction, which is not currently being done) because the initial table has 5,000,000+ rows and just grows larger every week, because we keep adding to it (this is basically an ETL process and the tables only get updated via the BULK INSERT). Besides, sp_rename adds hardly anything to the transaction log. I may do the rename outside the main transaction. If it fails, I can just not continue processing.
0
 
LVL 19

Expert Comment

by:elimesika
ID: 21776254
HI again

unfortunately , SQL server 2000 does not support commit of nested transactions, if that was supported , you was able to solve that in two inner transaction that are contained in outer transaction.
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 15

Author Comment

by:dbbishop
ID: 21778169
I am aware of that. I mean I can start one transaction for the rename (or actually, just check the error code after doing it) and if it successd, commit, then start another transaction for the other code. If the rename fails, I haven't lost a thing really. I still have the original table and no data has been processed.
0
 
LVL 19

Expert Comment

by:elimesika
ID: 21778858
Yes , SQL server ignores inner transaction commit .....
0
 
LVL 15

Author Comment

by:dbbishop
ID: 21778931
Yes, I know. I am talking about two transactions. If the first one produces an error, I will roll it back and not do the second one. If it suceeds, I'll commit it then begin a second transaction. I am not talking about nesting transactions, as I know only the final commit does anything.
0
 
LVL 15

Author Closing Comment

by:dbbishop
ID: 31466744
I went with this. Although I got it to work by making it two transactions, I realized that if the second transaction errored, I would have to add logic to rename the tables back to their original names, otherwise, they would not exist. Takes longer, but a bit easier.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question