TECH Easy SQL questions

stormchao

New Member
Apr 2, 2009
909
Jerz
What is the best method for updating a record if it exists, and if it does not exist I want to append a record? Do 'if' statements exist in SQL? I'm just a beginner. Basically something like...


I've got a record that is uniquely indexed on 2 fields, ComputerID and SoftwareID.

If (SELECT * FROM myTable WHERE ComputerID = # AND SoftwareID = #) EXISTS
UPDATE blah blah blah
ELSE
INSERT INTO blah blah blah
 

telc

OT Supporter
Aug 29, 2003
18,555
MySQL has "REPLACE INTO"

and SQL SERVER 2008 has "MERGE"

They will do an insert if the record does not exist, if the record exists it does an update.
 

Users who are viewing this thread

About Us

  • Please do not post anything that violates any Local, State, Federal or International Laws. Your privacy is protected. You have the right to be forgotten. Site funded by advertising, link monetization and member support.
OT v15.8.1 Copyright © 2000-2022 Offtopic.com
Served by fu.offtopic.com

Online statistics

Members online
437
Guests online
57
Total visitors
494

Forum statistics

Threads
369,464
Messages
16,885,830
Members
86,873
Latest member
vitalesan