Re: sql question
From: David Gugick (davidg-nospam_at_imceda.com)
Date: 02/16/05
- Next message: David Gugick: "Re: SQL Server Hardware requirements"
- Previous message: Anith Sen: "Re: sql question"
- In reply to: tina miller via SQLMonster.com: "sql question"
- Next in thread: tina miller via SQLMonster.com: "Re: sql question"
- Reply: tina miller via SQLMonster.com: "Re: sql question"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 16 Feb 2005 14:36:22 -0500
tina miller via SQLMonster.com wrote:
> How are these placed exactly in the program. Do you run at 1 time or
> different?
>
> Example:
>
> begin tran
> delete
> from enc
> where epsid = '23232'
> commit
>
> I ran the above then ran the following to undo:
>
> begin tran
> rollback tran
>
> That was it. I am not entirely sure how to put the transactions
> together to enable the rollback if the data being changed it not
> correct. This is a training issue and I can't run something that is
> an else if statement. I have to delete something from a table in 1
> entry and then go back an roll it back to what it was originally in
> another entry. I need the transaction to complete being deleted and
> view the table and see it is gone and then do a rollback and then
> another select and see it is back.
The first thing you can do is use a stored procedure instead of embedded
SQL, if possible. That way, all your code is in the procedure and the
transaction can be easily managed. in your case, you would send each
command to SQL Server and then commit or rollback as needed. Your code
above doesn't seem right though. In the first batch, you issue a BEGIN
TRAN and a COMMIT. In the second, you show a BEGIN TRAN AND ROLLBACK. By
the time th esecond batch runs, the first has already committed. The
second batch does nothing since there is no SQL, other than make a
couple roundtrips to the server.
What do you mean my data being changed is not correct? Do you mean if
the delete does not affect any rows? In that case, it wouldn't hurt to
commit since nothing was changed. Can you post exactly what you need to
do and also let us know whether you can use a stored procedure instead
of batch SQL.
-- David Gugick Imceda Software www.imceda.com
- Next message: David Gugick: "Re: SQL Server Hardware requirements"
- Previous message: Anith Sen: "Re: sql question"
- In reply to: tina miller via SQLMonster.com: "sql question"
- Next in thread: tina miller via SQLMonster.com: "Re: sql question"
- Reply: tina miller via SQLMonster.com: "Re: sql question"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
|