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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:34:53+00:00 2026-05-27T13:34:53+00:00

I have a question about updating table through t-sql. The client may want to

  • 0

I have a question about updating table through t-sql. The client may want to update one column in row and leave the rest unchanged or he may want to update multiple columns. So I have two solutions:

  1. Create one sp and update the whole table. The client has to provide all the parameters even if he wants to update a single column in a row so if he pass (which he has to) null for the parameters that he doesn’t have… well the original values will be lost. As a workaround I can use conditions to check for null parameters (different commands based on condition). However there is another issue, how can I recognize an int parameter? I mean suppose we have an int column that can have any integer values including zero so what should the client send to sp for saying “this is not a new value leave the value as is”.

  2. Create one sp per column. the client will use the appropriate sp to update a single column in a row so if he wants to update multiple columns he can call each related sp one after another and pass the two parameters which would be the row(s) id and the new value. What if I have a table with 25 updatable columns? Oh man! 25 update sp just for a single table!

Do I have to create an update sp per each table column? Or create one sp that takes all the row parameters and updates the whole table? What is the de-facto standard for writing update procedures?

EDIT1: i’m using sql server 2005 with front-end c# and asp.net app but i want to do it in t-sql.

  • 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-27T13:34:54+00:00Added an answer on May 27, 2026 at 1:34 pm

    If you truly must do this in T-SQL, then the only viable approach to me would be to use dynamic SQL. If you consider this, you must first read (and understand!) Erland Sommarskogs excellent essay The curse and blessings of dynamic SQL – absolute must-read!

    Basically, you’d have a single stored proc that takes your 25 parameters. Each of those can be NULL if it doesn’t need to be updated.

    Inside your stored proc, you basically build up your T-SQL UPDATE statement based on which parameters are non-NULL, and in the end, you execute that statement.

    This gives you one procedure, but that procedure will be quite messy to look at.

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

Sidebar

Related Questions

I have asked a question on SuperUser about updating Ruby version in Google SketchUp
I have a question that is driving me crazy. It is all about updating,
I have a question about aspnet_applications table I have created asp.net membership using .net
I have a question about updating variable inside dataTable component, which was sended to
I have a question about constraints in SQL, to be exact in transact-sql. I
I have a table with ~800k rows. I ran an update users set hash
Quick question/clarification required here. I have a DB table that will quite possibly have
So, I've got a design question: I have several processes running that are updating
I have a pretty large table: 20+ million rows and I need to update
I have a fairly huge database with a master table with a single column

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.