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

  • Home
  • SEARCH
  • 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 6746327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:18:34+00:00 2026-05-26T12:18:34+00:00

I have an asp.net web app where a user can update a table in

  • 0

I have an asp.net web app where a user can update a table in a database. I would like to know the proper method of doing this. As you can see in the image below, the red shaded area is the data that I have in common that I do not need to update.

enter image description here

Here are the steps that I need to take:

  1. Don’t update data if it exists
  2. Delete data that is not in the user update
  3. Add data from the user update that is not already in the table

I need to audit this table also, so I will have a trigger on it. I would like to know in theory what is the best way to do this kind of update to a table?

thank you to Aaron who introduced the concept of merge.

Here is what the table data looks like:

foreignkey  model  primarykey
1            AA       1
1            AA1      2
1            AA3      3
23           B        4
22           C        5

The user will be adding data that looks like this:

foreignkey  model  primarykey
1            A1       1
1            AA1      2
1            AA3      3
22           C        5

As you can see, the first row was updated, and the second to last row was deleted entirely. Can you please help me with this merge statement?

  • 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-26T12:18:34+00:00Added an answer on May 26, 2026 at 12:18 pm

    Yes, it’s possible and it’s called a merge. See the documentation for the SQL Server MERGE Statement.

    If you don’t want to perform any updates if the data already exists, then just don’t add a WHEN MATCHED clause. USE WHEN NOT MATCHED BY SOURCE and WHEN NOT MATCHED BY TARGET to insert/delete the missing/removed rows.

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

Sidebar

Related Questions

I have a asp.net/c# web app. When do user leave a certain page, I
I have a Silverlight web app which uses ASP.net Website administration tool for user
I have an asp.net update web app. Users go the the page, hit the
I have a SQL query in my ASP.net web app that looks like this:
We have a non-SSL ASP.NET web app that allows a user to login (ASP
Have an ASP.net web app which works fine for a few days, but then
I have a asp.net web forms app that uses System.Web.Caching.Cache to cache xml data
I have an ASP.NET 2.0 web app and part of the structure still has
In order to debug an asp.net web app I have to have IE Script
I have some configuration values for an asp.net web app. They will be maintained

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.