My C# program is doing the following (pseudo code):

```
START TRANSACTION READ COMMITTED
Select isOriginal, * from myTable where tnr = x;
//Record found?
Yes:
  //isOriginal? 
  Yes:
    update myTable set is_active = 0 where tnr = x;
  No:
    delete from myTable where tnr = x;
  //Do some simple logic on the values
  Insert into myTable (newvalues)
No:
  return record_not_found;
END TRANSACTION

```

However, when I start two instances of my program and both edit the same record at the same time two records are inserted as they both find the record in the select query.

What should happen is that the first transaction finds the record and inserts a new row while the second transaction returns a record not found.

How can I fix this? Put my transaction to serializable? Check the return value of update/delete? What's the best way?

*Edit*:

It should work on Sybase, Oracle & SQL Server.