Can I set ignore_dup_key on for a primary key?(我可以为主键设置 ignore_dup_key 吗?)
问题描述
我在一张表上有一个两列主键.我试图改变它以使用以下命令将 ignore_dup_key
设置为打开:
I have a two-column primary key on a table. I have attempted to alter it to set the ignore_dup_key
to on with this command:
ALTER INDEX PK_mypk on MyTable
SET (IGNORE_DUP_KEY = ON);
但我收到此错误:
不能使用索引选项 ignore_dup_key 来改变索引 'PK_mypk',因为它强制执行主要或唯一约束.
我还应该如何将 IGNORE_DUP_KEY
设置为打开?
How else should I set IGNORE_DUP_KEY
to on?
推荐答案
它没有记录在联机丛书中,但我发现虽然 IGNORE_DUP_KEY
对主键有效,但您无法更改它带有 ALTER INDEX;您必须删除并重新创建主键.
It's not documented in Books Online, but I've found that while IGNORE_DUP_KEY
is valid for Primary Keys, you can't change it with an ALTER INDEX; you'll have to drop and re-create the primary key.
请记住,IGNORE_DUP_KEY
不允许您在唯一索引中实际存储重复行,它只是改变失败方式当您尝试时:
Keep in mind that IGNORE_DUP_KEY
doesn't allow you to actually store duplicate rows in a unique index, it simply changes how it fails when you try it:
ON:插入重复键值时会出现警告信息成唯一索引.只有违反唯一性的行约束将失败.
ON: A warning message will occur when duplicate key values are inserted into a unique index. Only the rows violating the uniqueness constraint will fail.
OFF:插入重复键值时会出现错误信息成唯一索引.整个INSERT操作都会滚动返回.
OFF: An error message will occur when duplicate key values are inserted into a unique index. The entire INSERT operation will be rolled back.
来自 http://msdn.microsoft.com/en-us/library/ms175132.aspx
这篇关于我可以为主键设置 ignore_dup_key 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:我可以为主键设置 ignore_dup_key 吗?


基础教程推荐
- 带更新的 sqlite CTE 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01