I have some data records that may or may not exist already in my database. Right now when I want to update these records, I have to keep track of whether I got them from the DB, or created them from scratch, so that I know whether to make an INSERT or UPDATE query. I could query the database just before writing to find out if the record exists, so that I don't have to hang onto this state for the object's lifetime, but that's more database overhead than I'd like. Does SQL have anything to help me out here?
I'm using SQL Server 2005, in case there's some sort of engine-specific solution.