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 |
salmonraju
Yak Posting Veteran
54 Posts |
Posted - 2006-10-26 : 03:39:35
|
hi here in my code contains 3 sqlcommands 1st executes well2nd one will raise error because it mger is not matched with current row3rd also raise error because row doesnt existPLS GO THROUGH BELOW CODEBUT MY @ERROR IN THE 2ND SQL CONTAINS 0 INSTEAD SOME VALUE ,WHY IT HAPPENED SIMILAR TO 3RDcreate proc errChk as delete from Employees where DepartmentID=3 IF @@ERROR <> 0 BEGIN RAISERROR ('Error in deleting employees in DeleteDepartment.', 16, 1) --return end update Employees set mger='ooo' where DepartmentID=1 and mger='ravi' IF @@ERROR <> 0 BEGIN RAISERROR ('Error in updating employees in DeleteDepartment.', 16, 1) --return end delete from Employees where DepartmentID=10 IF @@ERROR <> 0 BEGIN RAISERROR ('Error in deleting employees in DeleteDepartment.', 16, 1) --return end |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-10-26 : 03:43:37
|
Raiserror gives an error back to front end application over the connection variable.Also, why do you think a DELETE statement raises an error? Maybe you should use @@ROWCOUNT?Peter LarssonHelsingborg, Sweden |
 |
|
salmonraju
Yak Posting Veteran
54 Posts |
Posted - 2006-10-26 : 04:28:24
|
hi pesoin book it is said that the usage of @@ERROR is check whether the statements has any errors this code is taken from a site it is not written by me |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-10-26 : 04:44:41
|
I think you have to read the article in the book again.An UPDATE statement that does not update a row because of wrong WHERE condition, does NOT raise an error. @@ROWCOUNT will be zero and so will @@ERROR.Peter LarssonHelsingborg, Sweden |
 |
|
salmonraju
Yak Posting Veteran
54 Posts |
Posted - 2006-10-26 : 07:44:42
|
Thank u Mr.Peter Larsson, will u sugggest me in what cases/situation @@error will be non zerowhat is the appropriate scenario to use @@ERRORI saw almost all programers are using @@error to check for errors,actually i have less knowledge about this please tell any information on this |
 |
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2006-10-26 : 07:49:34
|
one of the case can be, possibly that you are trying to insert or update the record into the table and there is an referantial indegrity problem and you will have the value of @@Error as Non -Zero. Secondly while inserting/updating the records, the column has the not null constraint and you are trying to insert the null value then @@Error will have non-zero value. Chiraghttp://chirikworld.blogspot.com/ |
 |
|
|
|
|
|
|