question

srikanth2413 avatar image
srikanth2413 asked

ALTER TABLE [dbo].[TestTable] WITH NOCHECK ADD CONSTRAINT [CK_CusRptC_TestColID] CHECK NOT FOR REPLICATION (([TestColID]=(3681)))

****** Object: Table [dbo].[TestTable] Script Date: 06/18/2014 15:57:51 ******/ I have a table script same as below. SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[TestTable]( [TestIdenID] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL, [TestColID] [smallint] NOT NULL, CONSTRAINT [PK_TestTable] PRIMARY KEY CLUSTERED ( [TestIdenID] ASC, [TestColID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO SET ANSI_PADDING OFF GO ALTER TABLE [dbo].[TestTable] WITH NOCHECK ADD CONSTRAINT [CK_CusRptC_TestColID] CHECK NOT FOR REPLICATION (([TestColID]=(3681))) GO ALTER TABLE [dbo].[TestTable] CHECK CONSTRAINT [CK_CusRptC_TestColID] GO ALTER TABLE [dbo].[TestTable] ADD CONSTRAINT [DF_CusRptCTestColID] DEFAULT ((3681)) FOR [TestColID] GO I am trying to insert the value using insert query same as below INSERT INTO TestTable(TestColID) VALUES (1224) But while trying to execute the query I am getting the Check constraint error. Could some one please explain the reason why I am getting that error. I have gone throught couple of blogs but I didn't get the solution. Please help me to understand the problem Thank you Srikanth
sqlquery
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
DenisT avatar image
DenisT answered
Well, you have a check constraint and it's doing what it's supposed to! This TestColId can only be equal to 3681. Try in insert 3681. ALTER TABLE [dbo].[TestTable] WITH NOCHECK ADD CONSTRAINT [CK_CusRptC_TestColID] CHECK NOT FOR REPLICATION (([TestColID]=(3681))) GO
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.