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 9201763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:05:50+00:00 2026-06-17T23:05:50+00:00

I am asking this question for knowledge only. I have SQL Server 2008 R2

  • 0

I am asking this question for knowledge only. I have SQL Server 2008 R2 and I have created a stored procedure in which I have five insert statements that execute one by one for different tables.

I don’t have placed any locks or transaction code in that stored procedure. Now what if the 3rd insert statement throws an error? Will the remaining two statements be executed or not?

Thanks

  • 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-06-17T23:05:51+00:00Added an answer on June 17, 2026 at 11:05 pm

    Based on the type of error, SQL Server will abort the statement or the batch. If it aborts the statement, the other inserts will still run. If it aborts the batch, the procedure is aborted and the remaining inserts are not run.

    Full details in an excellent article by Sommarskog from a comment by Martin Smith.

    Here’s an example setup. It contains a stored procedure TestProc that does six inserts. The third insert causes a foreign key violation, and the fifth insert causes a conversion error. Only the second error causes the stored procedure to stop:

    use test
    GO
    set nocount on
    IF OBJECT_ID(N't2', N'U') IS NOT NULL
        DROP TABLE t2;
    IF OBJECT_ID(N't1', N'U') IS NOT NULL
        DROP TABLE t1;
    IF OBJECT_ID(N'TestProc', N'P') IS NOT NULL
        DROP procedure TestProc
    GO
    CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY);
    CREATE TABLE t2 (a INT NOT NULL REFERENCES t1(a));
    GO
    create procedure TestProc
    as
    INSERT INTO t1 VALUES (1);
    INSERT INTO t1 VALUES (2);
    
    INSERT INTO t2 VALUES (3); -- Foreign key error (statement abort)
    INSERT INTO t2 VALUES (1); -- Still gets inserted
    INSERT INTO t2 VALUES ('a'); -- Conversion failed (batch abort)
    INSERT INTO t2 VALUES (2); -- Does *not* get inserted
    go
    exec TestProc
    go
    select * from dbo.t1
    select * from dbo.t2
    

    Output:

    Msg 547, Level 16, State 0, Procedure TestProc, Line 6
    The INSERT statement conflicted with the FOREIGN KEY constraint "FK__t2__a__035179CE".
    The conflict occurred in database "test", table "dbo.t1", column 'a'.
    The statement has been terminated.
    Msg 245, Level 16, State 1, Procedure TestProc, Line 8
    Conversion failed when converting the varchar value 'a' to data type int.
    a
    -----------
    1
    2
    
    a
    -----------
    1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am finally asking this question as I have never actually found an answer.
I'm asking this question because I have gone through the tutorial posted here: Preventing
This is more of knowledge sharing rather than asking a question. Thought this little
I appologize for asking this question, but i have searched and kind find anything
I'm asking this question with little/no knowledge of SMS gateways and it's relevant technologies,
In asking this question, I'm looking for either better understanding of the situation or
I searched before asking this question. I didn't find an answer probably because I
I am asking this question here because it is my understanding that this is
I searched SO before asking this question, I am completely new to this and
No luck asking this question on the AWS forum , so will try my

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.