Groups | Blog | Home
all groups > sql server programming > march 2004 >

sql server programming : Executing several batches


Maryam Teimourian
3/5/2004 11:21:07 PM
H
I have several batches.If an error occurs in one of these batches during execution,all batches run except the on that error has occured in it
How can I force it in the case of error that none of the batches execute
Maryam Teimourian
3/6/2004 2:51:05 AM
Dear Tibo
I have 2 batches
1-BULK INSER
2-UPDAT

Tibor Karaszi
3/6/2004 10:49:24 AM
Depends on what you want to accomplish. Say you have 5 batches, each
containing 3 modification statements. The 2:nd modification in the 3:rd
batch gives an error. What should the outcome be?
None of the modification performed?
None of the modifications in the 3: rd batch., not the 4:th and 5:th
performed?
Or just terminate the whole thing when you encounter an error and what has
been modified stays?

--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp


[quoted text, click to view]

Tibor Karaszi
3/6/2004 12:09:56 PM
Can you show the code? Did you check the error from the BULK INSERT and do a
ROLLBACK if the BULK INSERT weren't successful?

--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp


[quoted text, click to view]
data) but the update is done.Notice that I've executed these two batches
with transaction but result was the same.

Maryam Teimourian
3/6/2004 9:46:05 PM
Dear Tibo
I execute this code in Query Analyzer and @@ERROR doesn't work in Query Analyzer.How can I check if an error occurs
Here is my code

Use MYD
G
bulk insert MYTABLE1 from 'D:\MYFOLDER\X.txt
with (DATAFILETYPE = 'widechar'
FIELDTERMINATOR = ','
G
update MYTABLE2 set MYFIELD1 = MYFIELD1 +
Uri Dimant
3/8/2004 9:42:48 AM
Hi,Maryam
I did a small test which create two tables and attempt to insert values.
I plaied with SET XACT_ABORT when it is ON and the query raises an error
the entire of transction is terminated and rolled back.
Try to modify it for your needs and see if it helps.

create table t1 ( col char(1))
create table t2 ( col int)

SET XACT_ABORT OFF
begin tran
insert into t1 values ('aa') ------ raises a run-time error
insert into t2 values (1)
commit

drop table t1,t2



[quoted text, click to view]

AddThis Social Bookmark Button