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
 Transact-SQL (2000)
 database script error handling

Author  Topic 

krunal1
Starting Member

2 Posts

Posted - 2008-01-10 : 10:21:02
~>i have one database script there is a lots of sql statements in one script
and I run this script in sql analyzer 2000.

For Example:
line 1 : alter table1
line 2 : alter table2
line 3 : alter table3
line 4 : alter table4

line 6 : insert into table1 ..................
line 7 : update into table2 ..................
line 8 : delete from table1 where ..................
line 9 : insert into table3 ..................
line 10 : update into table4 ..................

line 11: drop stored procedure SP1
line 12: drop stored procedure SP2
line 13: drop stored procedure SP3
line 14: drop stored procedure SP4

line 15 : create stored procedure SP1
line 17: create stored procedure SP2
line 18 : create stored procedure SP3
line 19 : create stored procedure SP4

suppose there is an error in line number 4 i want to execute the next statement after line number 4 upto line number 19

I want to handle error in this database script

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-01-10 : 10:41:46
Didnt understand the purpose of this requirement?
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-01-10 : 10:41:48
quote:
Originally posted by krunal1

~>i have one database script there is a lots of sql statements in one script
and I run this script in sql analyzer 2000.

For Example:
line 1 : alter table1
line 2 : alter table2
line 3 : alter table3
line 4 : alter table4

line 6 : insert into table1 ..................
line 7 : update into table2 ..................
line 8 : delete from table1 where ..................
line 9 : insert into table3 ..................
line 10 : update into table4 ..................

line 11: drop stored procedure SP1
line 12: drop stored procedure SP2
line 13: drop stored procedure SP3
line 14: drop stored procedure SP4

line 15 : create stored procedure SP1
line 17: create stored procedure SP2
line 18 : create stored procedure SP3
line 19 : create stored procedure SP4

suppose there is an error in line number 4 i want to execute the next statement after line number 4 upto line number 19

I want to handle error in this database script



alter table error is a batch breaking error and further code won't execute:

-- errors with: Incorrect syntax near the keyword 'COLUMN'.
ALTER TABLE YourExistingTable ADD COLUMN gg INT
-- select doesn't execute
SELECT 1

-- errors with: Incorrect syntax near the keyword 'COLUMN'.
ALTER TABLE YourExistingTable ADD COLUMN gg INT
GO
-- select executes
SELECT 1


_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com <- new version out
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2008-01-10 : 10:43:55
As the others said, you never really asked an explicit question so to expand on what Spirit1 said:

There are certain errors that will halt execution of sql code in the batch (between GO statements) so any traditional error handler won't catch those erros. ie: referring to an object that does not exist will halt execution. So you need to anticipate those types of errors and test for the condition before attempting the action. In the case of a missing object, "if object_id('<objName>') > 0"

Look at Books Online for "control of flow" techniques like GOTO.

There are a host of techniques you can use to know what state your process is in and control what should execute. Search forums here on "error handling" there will be lots of topics.


Be One with the Optimizer
TG
Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2008-01-10 : 10:55:04
http://sommarskog.se/error-handling-II.html
http://sommarskog.se/error-handling-I.html


elsasoft.org
Go to Top of Page

krunal1
Starting Member

2 Posts

Posted - 2008-01-16 : 01:24:05
quote:
Originally posted by visakh16

Didnt understand the purpose of this requirement?




actually when we did the some changs in table or procedure at the time of delivery of new change sofware setup we also send the database script for aletration in table or storedprocedure now before sending this script to client we check the scrpit at that time i require to test script
Go to Top of Page
   

- Advertisement -