Solved

pervasive sql transaction

Posted on 2011-03-15
3
1,142 Views
Last Modified: 2013-12-25
Hello everyone,

I am somewhat new to pervasive sql and I was wondering if I can run a series of sql statements as a transaction.   IE I am trying to duplicate a few records in a database with new keys and then delete the old record but only if all the inserts worked properly

insert into xtable (columna, columnb) select '12345', columnb from xtable where columna = '23456'

insert into ytable (columnd, columne, columnf) select '444444', columne, columnf from ytable where columnd = '33333'

delete from xtable where columna = '23456'
delete from ytable where columnd = '33333'

if any of those fail I want to rollback the transaction.

Any thoughts on how I would do this?

thanks in advance..
0
Comment
Question by:mitai
[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
  • 2
3 Comments
 
LVL 28

Expert Comment

by:Bill Bach
ID: 35140014
Yes.  Issue BEGIN TRANSACTION at the beginning, and then END TRANSACTION at the end to commit it.  I believe ABORT TRANSACTION is used to abort and undo the changes.
0
 

Author Comment

by:mitai
ID: 35141143
OK, I will try that.  How do you test to see if an error occured on each of the sql statements?
0
 
LVL 28

Accepted Solution

by:
Bill Bach earned 500 total points
ID: 35143362
A SELECT @@ROWCOUNT might work for you.  You can read this into a variable, and if ROWCOUNT > 0, then the operation was successful.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
Steps to create a PostgreSQL RDS instance in the Amazon cloud. We will cover some of the default settings and show how to connect to the instance once it is up and running.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

749 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