SQL Server 中的唯一密钥冲突 - 假设错误 2627 是否安全? [英] Unique Key Violation in SQL Server - Is it safe to assume Error 2627?
本文介绍了SQL Server 中的唯一密钥冲突 - 假设错误 2627 是否安全?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要通过我正在开发的 C# 应用程序以特殊方式捕获对 UNIQUE
约束的违反.假设 Error 2627
将始终对应于此类违规是否安全,以便我可以使用
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.
}
?
推荐答案
2627是唯一约束(包括主键),2601是唯一索引
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
这篇关于SQL Server 中的唯一密钥冲突 - 假设错误 2627 是否安全?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文