Solved

Transaction Processing - Using SQL Server 2000

Posted on 2008-06-12
7
200 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
  • 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
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
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.

863 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now