I have some records that I want to "insert or update" into a SQL Server database, via a stored procedure. These records have a globally unique and stable ID, and a bunch of value attributes (about a dozen).

Checking for insert is straightforward enough - see if the key doesn't exist in the table.

Assuming that the key does exist, I then need to check whether the existing record contains exactly the same values as the current data that I'm passing into the procedure. At the moment I'm doing this via:

```
SELECT @identical = CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END FROM Table
    WHERE idCol = @newId
      AND valueCol1 = @newValue1
      AND valueCol2 = @newValue2
      AND ...

```

This works, but it's not very efficient; I'm able to insert about 70 records per second which is a lot slower than I'd expect.

My first thought was to add an index - but this will be indexing almost every column in the table. Would that even make sense or would it just be a second copy of the table? (The ID column is a clustered PK if that's relevant.)

Is there any sensible way to speed up a query that has to check the values of every column? I'm considering using some sort of hash to detect duplicates, but this adds some space overhead, complexity to the sprocs and small (acceptable) possibility of false positives, so I'd much rather a solution based on indices or rewriting the SQL if one exists.