Solved

Transaction Processing - Using SQL Server 2000

Posted on 2008-06-12
7
203 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Query Optimization 14 45
Abstract Express Replacement Software 12 28
SQL server vNext 18 29
abs operation in sql server 15 15
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

803 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