Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

UPDATE or INSERT even if row exists

Status
Not open for further replies.

bthale

Programmer
Joined
Oct 31, 2001
Messages
108
Location
US
Our application does the following when inserting or updating a record

1. Check to see if the record exists
2. If it exists - do an UPDATE else do an INSERT

I'm wondering if there is a way to do one or the other without making the query to see if it exists in the first place. I know about uniqueness and constraints, but what I would like to do is make one call and it either updates or inserts depending on the existence of the record. A stored procedure is kind of tough because some of the records may have up to 20 columns/parameters.

Can this be done?
 
You would use a "IF EXISTS" clause to perform the desired action

Thanks

J. Kusch
 
Sounds OK, but then I still have to make a call to insert if it doesn't exist. I guess that if half are updates and half are inserts then I could cut down the DB calls in half the cases.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top