Elementary T-SQL Question
From: News (n.sutter_at_comcast.net)
Date: 06/04/04
- Next message: Daniel: "setting up a database in msde"
- Previous message: Mingqing Cheng [MSFT]: "RE: sqldmo failed to register"
- Next in thread: Tibor Karaszi: "Re: Elementary T-SQL Question"
- Reply: Tibor Karaszi: "Re: Elementary T-SQL Question"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 4 Jun 2004 13:09:47 -0500
Hi,
Probably an easy solution, but I can't find it.
Trying to find a way to create a SQL script that either completes
successfully or stops executing the rest of the code in the source file when
an error occurs. Most of these scripts update a single table in some
fashion. Occassionally a script that works in one location won't work at
another site; so a graceful error detection and exit is desired. (The source
files containing each script are executed via ISQL. And multiple sequential
calls to ISQL are linked together in a CMD file.)
Each SQL script generally does something like the following:
Drop the existing backup table, if it exists
Create a backup table structured like the current primary table
Populate the backup table from the primary table
Drop the primary table
Re-create the primary table (new columns, re-defined or re-ordered columns,
whatever)
Populate the new primary table from the backup table
Drop the backup table.
All of this code is in a single input source file. But it is more than one
batch as there are 'GO's between each of the above statements. This sequence
works fine, .... as long as it works. But when an error occurs, then I'd
like to be able to detect the error and stop processing the rest of the
source file.
I've tried testing for @@ERROR after each statement and using RETURN xxx
when an error is detected, but the compiler doesn't allow numeric returns
unless in a SP.
Besides the return statement apparently only exits the batch it is contained
in; it doesn't stop processing the rest of the source file.
I've tried using local variables in the source file, but, again, these seem
to be local to the batch only, not the duration of the source file.
So, what have I missed.
Thanks for any help you can offer.
Neil Sutter
- Next message: Daniel: "setting up a database in msde"
- Previous message: Mingqing Cheng [MSFT]: "RE: sqldmo failed to register"
- Next in thread: Tibor Karaszi: "Re: Elementary T-SQL Question"
- Reply: Tibor Karaszi: "Re: Elementary T-SQL Question"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|