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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:07:50+00:00 2026-06-14T01:07:50+00:00

I want to update multiple rows in my database, the values might be different.

  • 0

I want to update multiple rows in my database, the values might be different. Imagine this table:

Username   FirstName   LastName 
-------------------------------
user1      John        Doe 
user2      Jane        Doe
user3      bill        gates

If I want to update the table so it looks like this:

Username   FirstName   LastName 
-------------------------------
user1      John        Deer 
user2      Jane        Farmer
user3      Gill        Bates

Is it best to use one UPDATE statement for each user? Or is it possible to do this with one query?

Also is it possible to put it in a stored procedure and provide a collection of values?

Second question is it best to check if the values are changed before doing an update? Or just update everyone even if the value is the same?

I am currently using SQL Server 2005 and C# for the application if that is relevant.

  • 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-14T01:07:51+00:00Added an answer on June 14, 2026 at 1:07 am

    You can try this

    declare @TempTable1 table (UserName nvarchar(128) primary key, FirstName nvarchar(128), LastName(128))
    
    insert into @TempTable1
    select 'user1', 'John', 'Deer' union all
    select 'user2', 'Jane', 'Farmer' union all
    select 'user3', 'Gill', 'Bate'
    
    update table1 set
        FirstName = t2.FirstName,
        LastName = t2.LastName
    from table1 as t
        inner join @TempTable1 as t2 on t2.UserName = t.UserName
    

    Or if you want to update only changed fields

    update table1 set
        FirstName = isnull(t2.FirstName, t.FirstName),
        LastName = isnull(t2.LastName, t.LastName)
    from table1 as t
        inner join @TempTable1 as t2 on t2.UserName = t.UserName
    

    For C# client application I think usual way is to create procedure

    create procedure sp_Table1_Update
    (
        @UserName nvarchar(128),
        @FirstName nvarchar(128),
        @LastName nvarchar(128)
    )
    as
    begin
        update table1 set
            FirstName = @FirstName,
            LastName = @LastName
        where UserName = @UserName
    end
    

    and then call it from your application for each user

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

Sidebar

Related Questions

I'm new to MySQL. I'm using this to update multiple rows with different values,
What I want to do is update multiple documents with different values in 1
I am trying to update multiple rows with different values, but don't need to
I want to select multiple rows from checkbox and want to update them all
i want to update multiple value of my table ORDRE ? table ORDRE CP
Can we add multiple rows in the database table from one JSF page in
I want the user to update multiple rows at once so I created a
This is basically an extension of Update multiple rows with one query? . I
I can't seem to find this anywhere, but I'm trying to update multiple rows
I want to update multiple rows like below update mytable set s_id = {0}

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.