Solved

Transaction Processing - Using SQL Server 2000

Posted on 2008-06-12
7
209 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

736 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