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.
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 table1line 2 : alter table2line 3 : alter table3line 4 : alter table4line 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 SP1line 12: drop stored procedure SP2line 13: drop stored procedure SP3line 14: drop stored procedure SP4line 15 : create stored procedure SP1line 17: create stored procedure SP2line 18 : create stored procedure SP3line 19 : create stored procedure SP4suppose 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? |
 |
|
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 table1line 2 : alter table2line 3 : alter table3line 4 : alter table4line 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 SP1line 12: drop stored procedure SP2line 13: drop stored procedure SP3line 14: drop stored procedure SP4line 15 : create stored procedure SP1line 17: create stored procedure SP2line 18 : create stored procedure SP3line 19 : create stored procedure SP4suppose 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 executeSELECT 1-- errors with: Incorrect syntax near the keyword 'COLUMN'.ALTER TABLE YourExistingTable ADD COLUMN gg INTGO-- select executesSELECT 1 _______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenpSSMS Add-in that does a few things: www.ssmstoolspack.com <- new version out |
 |
|
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 OptimizerTG |
 |
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
|
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 |
 |
|
|
|
|