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 2008 Forums
 Transact-SQL (2008)
 stored procedure failed, but kept running

Author  Topic 

scabral7
Yak Posting Veteran

57 Posts

Posted - 2010-10-25 : 12:09:06
HI,

I have a sql 2008 stored procedure and the first step is to drop an index, then it does an insert into the table, then recreates the index.

However, yesterday the procedure failed when it tried to drop the index becasue it didn't exist, which makes sense. But it kept running and still did the insert and created the index.

Is this how a stored proc usually functions when it hits an errror? Is there a way to make it stop running the rest of the stored procedure?

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2010-10-25 : 13:36:06
First, you should be testing for the existence of the index b4 attempting to drop it.

to make the script stop running when it encounters an error:
Begin Try
-- do something that might not work
End Try

Begin Catch
Return
End Catch

-- Do some other stuff
Go to Top of Page
   

- Advertisement -