I am trying to add a relationship between 2 tables, but i am getting the “The ALTER TABLE statement conflicted with the FOREIGN KEY constraint” error.
This is because there is some data in one of the tables that doesnt match the data in the other table.
I want to add the NOCHECK option, so that it wont check if the data is accurate. How can i do this using MSSMS?
Example:
BEGIN TRANSACTION
SET QUOTED_IDENTIFIER ON
SET ARITHABORT ON
SET NUMERIC_ROUNDABORT OFF
SET CONCAT_NULL_YIELDS_NULL ON
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.Column_Definition SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.Tabelform_Answers ADD CONSTRAINT
FK_Tabelform_Answers_Column_Definition FOREIGN KEY
(
column_id
) REFERENCES dbo.Column_Definition
(
id
) ON UPDATE NO ACTION
ON DELETE NO ACTION
GO
ALTER TABLE dbo.Tabelform_Answers SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
For your query:
Reference to MSDN article on ALTER TABLE