BUG: Check Constraint Is Not Enforced if Marked "Not for Replication"

ID: Q246323


The information in this article applies to:
  • Microsoft SQL Server version 7.0

BUG #: 56174 (SQLBUG_70)

SYMPTOMS

When a table is created with check constraint and the constraint is set as "NOT FOR REPLICATION", the constraint is not enforced even though the value entered is outside the range of the check constraint. For example:

  1. Create a table with check constraint not for replication:


  2. 
    use pubs
    go
    
    CREATE TABLE dbo.test5
    (
    abc int NOT NULL
    ) ON [PRIMARY]
    
    go
    ALTER TABLE dbo.test5 ADD CONSTRAINT
    CK_test5 CHECK NOT FOR REPLICATION ((abc>0)) 
  3. Insert a new row:


  4. 
    INSERT INTO pubs..test5 (abc) VALUES (1) 
  5. Update the same row:


  6. 
    UPDATE pubs..test5 SET abc=-1 WHERE abc=1 
The preceding update should create this error:
Server: Msg 547, Level 16, State 1, Line 1
UPDATE statement conflicted with COLUMN CHECK constraint 'CK_test5'. The conflict occurred in database 'pubs', table 'test5', column 'abc'.
The statement has been terminated
On the contrary, the preceding update is actually successful.


WORKAROUND

Do not use the "NOT FOR REPLICATION" option on CHECK CONSTRAINT.


STATUS

Microsoft has confirmed this to be a problem in SQL Server version 7.0.


MORE INFORMATION

Also, when you trying to change the value in the preceding example back to a value that is within the range as in this example:


UPDATE pubs..test5 SET abc=1 WHERE abc=-1 
You may see this error message:
attempt made to perform direct %s to range that is maintained by replication. The conflict occurred in database '%s, table %s, column %s

Additional query words:

Keywords : kbSQLServ700bug
Version : winnt:7.0
Platform : winnt
Issue type : kbbug


Last Reviewed: January 6, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.