Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6384555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:47:24+00:00 2026-05-25T02:47:24+00:00

Below is the code for my stored procedure but I am not completely clear

  • 0

Below is the code for my stored procedure but I am not completely clear with the flow of execution. How the @@RAISERROR() in my case will work and how it will change the normal flow? Also what does the number 10 & 1 mean in that function. There are few other numbers also that can be used instead of 10 & 1 so how all the number affects flow of execution. Please let me know if my coding structure of style is bad/wrong or if there is any scope for improvement.
Below is my code.

CREATE PROCEDURE spAddressMaster 
@Mode           varchar(20),
@Street         varchar(MAX),
@City           varchar(300),
@State          varchar(300),
@Country        varchar(300),
@PostalCode     int,
@Remarks        varchar(MAX),
@Type           varchar(300)
AS
BEGIN
BEGIN TRANSACTION
BEGIN TRY
--INSERT MODE--
IF(@Mode='INSERT')
BEGIN
    INSERT INTO [AddressMST] (
                [Street],
                [City],
                [State],
                [Country],
                [PostalCode],
                [Remarks],
                [Type]
                )
    VALUES (
        @Street,
        @City,
        @State,
        @Country,
        @PostalCode,
        @Remarks,
        @Type
    ) 
IF(@@ERROR<>0)
    RAISERROR('Insert Operation Fail',10,1)
END
END TRY
BEGIN CATCH
    IF(@@ERROR<>0)
    BEGIN
        ROLLBACK TRANSACTION
        SELECT ERROR_MESSAGE()
    END 
END CATCH
END
GO
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:47:25+00:00Added an answer on May 25, 2026 at 2:47 am

    First off, you have a big problem: you have a BEGIN TRANSACTION without any COMMIT. That’s about as wrong as you can get when programming for databases! Use this general structure:

    BEGIN TRANSACTION
    
    BEGIN TRY
    
    …do stuff…
    
    COMMIT
    END TRY
    
    BEGIN CATCH
    
    …error handling…
    
    ROLLBACK
    
    END CATCH
    

    Next up, when you are executing code within a BEGIN TRY block, if any errors are raised execution is immediately transferrred to the BEGIN CATCH block. This means that the IF(@@ERROR<>0) block will only ever be executed when no errors have occured, i.e. @@ERROR will always be 0.

    As for the meaning of the 10 and 1 in the RAISERROR, that is complex, detailed, and best explained in SQL Server books online under the entry “RAISERROR”. Here’s the Link.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the code below to query records from a stored procedure but am
When making an HttpWebRequest within a CLR stored procedure (as per the code below),
The below code seems like it should work; however, the blob in the database
I'm wondering how i can improve my Zend code that calls a stored procedure.
How do I create a stored procedure that exists in one database but runs
Aim: Calling a very slow stored procedure (with parameters) asynchronously from code behind of
Okay basically I am creating a stored procedure that will return data for our
This is the code from stored procedure of SQL server. I have declared constant
I've got code similar to the following in a stored procedure that inserts a
I have written a stored procedure given below....it should print the values I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.