Unique Key Violation in SQL Server - Is it safe to assume Error 2627?
sql-server-2005, unique-constraint
Solution
2627 is unique constraint (includes primary key), 2601 is unique index
SELECT * FROM sys.messages
WHERE text like '%duplicate%' and text like '%key%' and language_id = 1033
Problem
I need to catch violation of `UNIQUE` constraints in a special way by a C# application I am developing. Is it safe to assume that `Error 2627` will always correspond to a violation of this kind, so that I can use ``` if (ThisSqlException.Number == 2627) { // Handle unique constraint violation. } else { // Handle the remaing errors. } ``` ?