Msg 547 The ALTER TABLE statement conflicted with the CHECK constraint "".
2012-10-19 11:59
651 查看
创建约束出现下面的错误:
Msg 547, Level 16,State 0, Line 2
The ALTER TABLEstatement conflicted with the CHECK constraint "chk_id". The conflictoccurred in database "test", table "dbo.test_CONSTRAINT",column 'ID'.
这个错误说明现有的表中数据超过了约束的限制,所以无法插入。一般我们需要将表中数据梳理完之后重新创建,但是可能存在一种状况比如以前确实只有5位的数据,现在升级系统后变为8位以前的数据还要保留。解决这个问题可以使用WITH
NOCHECK参数。
CREATE TABLE test_CONSTRAINT
(
ID INT
)
--插入一条记录误
INSERT INTO test_CONSTRAINTVALUES(100000)
select *
fromtest_CONSTRAINT
--创建约束(只允许-10000)
ALTER TABLE dbo.test_CONSTRAINTADDCONSTRAINT id_checkCHECK(id
between 1and 10000);
Msg 547, Level 16,State 0, Line 2
The ALTER TABLEstatement conflicted with the CHECK constraint "chk_id". The conflictoccurred in database "test", table "dbo.test_CONSTRAINT",column 'ID'.
--WITH NOCHECK 以避免根据现有行验证该约束,从而允许添加该约束
ALTER TABLE dbo.test_CONSTRAINTWITHNOCHECK
ADD CONSTRAINT id_checkCHECK(id
between 1and 10000);
-- 重新启用约束
ALTER TABLE dbo.test_CONSTRAINTCHECKCONSTRAINTid_check;
--插入违反约束的数据报错
INSERT INTO test_CONSTRAINTVALUES(100000)
Msg 547, Level 16,State 0, Line 1
The INSERTstatement conflicted with the CHECK constraint "id_check". Theconflict occurred in database "test", table"dbo.test_CONSTRAINT", column 'ID'.
The statement hasbeen terminated.
更多信息:http://msdn.microsoft.com/zh-cn/library/ms179491(v=sql.105).aspx
Msg 547, Level 16,State 0, Line 2
The ALTER TABLEstatement conflicted with the CHECK constraint "chk_id". The conflictoccurred in database "test", table "dbo.test_CONSTRAINT",column 'ID'.
这个错误说明现有的表中数据超过了约束的限制,所以无法插入。一般我们需要将表中数据梳理完之后重新创建,但是可能存在一种状况比如以前确实只有5位的数据,现在升级系统后变为8位以前的数据还要保留。解决这个问题可以使用WITH
NOCHECK参数。
CREATE TABLE test_CONSTRAINT
(
ID INT
)
--插入一条记录误
INSERT INTO test_CONSTRAINTVALUES(100000)
select *
fromtest_CONSTRAINT
--创建约束(只允许-10000)
ALTER TABLE dbo.test_CONSTRAINTADDCONSTRAINT id_checkCHECK(id
between 1and 10000);
Msg 547, Level 16,State 0, Line 2
The ALTER TABLEstatement conflicted with the CHECK constraint "chk_id". The conflictoccurred in database "test", table "dbo.test_CONSTRAINT",column 'ID'.
--WITH NOCHECK 以避免根据现有行验证该约束,从而允许添加该约束
ALTER TABLE dbo.test_CONSTRAINTWITHNOCHECK
ADD CONSTRAINT id_checkCHECK(id
between 1and 10000);
-- 重新启用约束
ALTER TABLE dbo.test_CONSTRAINTCHECKCONSTRAINTid_check;
--插入违反约束的数据报错
INSERT INTO test_CONSTRAINTVALUES(100000)
Msg 547, Level 16,State 0, Line 1
The INSERTstatement conflicted with the CHECK constraint "id_check". Theconflict occurred in database "test", table"dbo.test_CONSTRAINT", column 'ID'.
The statement hasbeen terminated.
更多信息:http://msdn.microsoft.com/zh-cn/library/ms179491(v=sql.105).aspx
相关文章推荐
- Msg 547 The ALTER TABLE statement conflicted with the CHECK constraint "".
- The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "FK_SortId".
- SQL SERVER 2005删除维护作业报错:The DELETE statement conflicted with the REFERENCE constraint "FK_subplan_jo
- SQL SERVER 2005删除维护作业报错:The DELETE statement conflicted with the REFERENCE constraint "FK_subplan_job_id"
- SQL SERVER 2005删除维护作业报错:The DELETE statement conflicted with the REFERENCE constraint "FK_subplan_job_id"
- The INSERT statement conflicted with the FOREIGN KEY constraint
- 170.A constraint in a table is defined with the INITIALLY IMMEDIATE clause. You executed the ALTER T
- Applying GI PSU "opatch auto" fails with "The opatch Component check failed"
- two improvement to the "drop all table with T-SQL" solution
- "The string '__checksum' was not found in the string table"解决办法
- 10.Examine the following statement that is used to modify the constraint on the SALES table:
- @Table(name = "", uniqueConstraints = @UniqueConstraint(columnNames = ""))
- yii提示The table "xxx" for active record class "DistAR" cannot be found in the database
- Failed to apply package protection with error 0xC0014061 "The protection level, ServerStorage, cannot be used when savin
- android出现the project was not built due to "a resource exists with a different case问题
- 交叉调试时arm-linux-gdb提示:No symbol table is loaded. Use the "file" command.
- The CREATE DATA statement with built-in generic types
- WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
- Fixing the "There is already an open DataReader associated with this Command which must be closed first." exception in Entity Framework
- 14、 iOS "The sandbox is not in sync with the Podfile.lock"解决方案