How to use INSERT or UPDATE on SQL Server

1149745 pts.
Tags:
SQL Server
SQL Server database
In our SQL Server database, we have a table structure like this:
MyTable(KEY, datafield1, datafield2...)
Sometimes, we need to either update an existing record or just insert a new one if you doesn't exist. Basically, this is what we want to run:
IF (key exists)
  run update command
ELSE
  run insert command
What would be the best way to write this? Thank you so much.
0

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • ToddN2000
    Where is the program going to be run from and what language do you need?
    134,720 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: