Solved

Transaction Processing - Using SQL Server 2000

Posted on 2008-06-12
7
197 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
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…

762 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

16 Experts available now in Live!

Get 1:1 Help Now