我可以为主键设置 ignore_dup_key 吗?

Can I set ignore_dup_key on for a primary key?(我可以为主键设置 ignore_dup_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 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)