Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 sql server scripts

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-09-27 : 09:09:07
andy writes "I have to run database upgrade scripts for our product on both sql server and oracle, and what I need to do is this:

1. log the script output and any errors in a file.

2. if any errors are detected in the script, the script is halted at that point.

For oracle i can do the first one with a spool command and the second with a "whenever sqlerror exit failure". For sql server I'm struggling to find an equivalent.

thanks for any help."

clarkbaker1964
Constraint Violating Yak Guru

428 Posts

Posted - 2004-09-27 : 19:42:45
I believe you would have to check the @@Error object after every statement place the entire script in a transaction then run a goto and a rollback... However if the script has GO statements you will have scope issues. You may have to convert the statements to executable text ie

Declare @MyError as int, @Sql as Nvarchar(4000)
Begin Tran
Set @Sql = 'USE BUFORD_DEV'
Exec sp_executesql @sql
@MyError = @@Error
If @MyError <> 0 then Goto ExitMyScript

ExitMyScript:
If @MyError<>0 Then
RollBack Tran
Else
Commit Tran



Surf On Dude!
Go to Top of Page
   

- Advertisement -