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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:03:54+00:00 2026-06-07T12:03:54+00:00

I have a stored procedure that updates two tables. The first table is always

  • 0

I have a stored procedure that updates two tables. The first table is always the same table, but the second table changes depending on a parameter that is passed in. Is it more efficient to write it all into one big procudure, as such

CREATE PROCEDURE MyBigProc
    @id int
    @param int,
    @value1 int,
    @value2 int
AS
BEGIN
    SET NOCOUNT ON;

    -- First table to update
    UPDATE MyTable SET field1 = @value1 WHERE id = @id

    -- Then choose which table to update based on @param
    IF @param = 1
       UPDATE MySecondTable SET field2 = @value2 WHERE id = @id

    IF @param = 2
       UPDATE MyThirdTable SET field2 = @value2 WHERE id = @id
END

Or should I write a separate procedure for each table and then call EXEC the procedure from the main procedure.

I suppose the latter is more flexible, say if I wanted to update a subtable but no the main table?

  • 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-07T12:03:56+00:00Added an answer on June 7, 2026 at 12:03 pm

    I suppose the latter is more flexible, say if I wanted to update a
    subtable but no the main table?

    Exactly, you have a good reason to split the work on 2 separate procs. If it makes sense for you for everything else, I don’t see why not follow that approach.

    One possible reason not to do it, would be if you need both updates to succeed or fail at the same time. Under a scenario like this, I would leave everything in one proc and enclose everything in one transaction.

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

Sidebar

Related Questions

I have a stored procedure that updates a table using linq, eg: (this is
I have a stored procedure that updates data in a table for a specific
I have a stored procedure that returns two int Values. The first can not
I have a stored procedure that takes no parameters, and it returns two fields.
I have an application that queries and updates two databases at the same time
I have a stored procedure in a MS-SQL 2005 database that: Creates two temp
I have a stored procedure that updates my database. It runs great in query
I use begin transaction in my stored procedure. I have code that updates data:
I have a stored procedure that says update table1 set value1 = 1 where
I have a stored procedure that has the parameter: @desk VARCHAR(50) I want to

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.