Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • Side note: the viability of even the hacky answer depends entirely on the proper ISOLATION_LEVEL being used. To prevent duplicate rows, you'll need to use SERIALIZABLE (because REPEATABLE_READ allows phantom reads) which, if you don't have an index on the column (and use the query shown here), is going to lock the entire table. Commented Apr 30, 2018 at 18:44
  • It's a terrible hack all around. I didn't really want to make it any more bulletproof because it shouldn't even be considered as a solution. Putting an index on the TestValue column will make this go lots faster... but then why not just turn the dial, make it a unique index and walk away. I should have also joined onto the INSERTED table (on TestValue) to help limit what was scanned, but it's still terrible. Commented Apr 30, 2018 at 19:00
  • 3
    Hey Jonathan, I've taken the liberty of giving your two suggestions a slightly different spin: reasonable vs less reasonable, instead of short vs long which didn't really make sense to me, as they are completely different suggestions rather than different wordings of the same suggestion. I also accompanied that with minor formatting/arrangement changes – all of them purely to reflect my view of how this answer could look better. Naturally you don't have to agree with any of my changes and I'm perfectly happy if you decide to roll them back, cheers. Commented Apr 30, 2018 at 19:19