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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:01:12+00:00 2026-06-03T22:01:12+00:00

I like to use Upsert stored procedures that update records if they exist or

  • 0

I like to use Upsert stored procedures that update records if they exist or insert them if they don’t. Without them, I would need to first find out if the record exists, and then have two separate stored procedures that I would call based on the result.

I never really thought about the issue before today when I was creating a stored procedure called UpdateOrDeleteRow. As soon as I found myself including “Or” in the name, my SRP spider sense kicked in, and I realized that the upserts are basically the same thing.

Is this a violation of SRP? If so, is it acceptable? If not, what should I do?

I realize that the SRP is an OOP principle, and T-SQL is not an OOP language, but the basis for the principle seems like it should apply here as well.

  • 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-03T22:01:13+00:00Added an answer on June 3, 2026 at 10:01 pm

    Personally I don’t believe that this principle applies completely in SQL Server. Stored procedures don’t always perform just one action (and I think the notion that a stored procedure is equivalent to a class is flawed). I don’t think it makes sense to split every single statement in a stored procedure into its own stored procedure. You can get absolutely ridiculous with this.

    There is a balance of course, as you can be ridiculous the other way. You don’t want a stored procedure with 18 different ways to specify parameters so that it can do 540 different things based on the combinations.

    For an UPSERT I would still suggest that a single stored procedure is fine for this. If you want to feel better about it serving a single purpose, change your update/insert into a single MERGE. 🙂 That said, and in all seriousness, be very careful with MERGE.

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

Sidebar

Related Questions

I would like use argparse to parse the arguments that it knows and then
http://en.wikipedia.org/wiki/Upsert Insert Update stored proc on SQL Server Is there some clever way to
I currently have some large strings that I would like use as test data
I like to use MySQL to do quantitative analysis and statistics. I would like
I would like to use the group_by method, but instead of using a column
I'd like to use PowerShell as part of our automated build process to update
I would like to use complex numbers as defined in C99, but I need
I would like use a panel whose children have coordinates specified as percentage of
I'm stuck now, in a background page, I would like use the .html() jQuery
I would like use Spring.NET for IoC , DI, AOP and Caliburn as MVVVM

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.