小编Sim*_*ice的帖子

The ALTER TABLE statement conflicted with the FOREIGN KEY constraint

I am trying to add a new foreign key to an existing table where there is data in the column I am wanting to make a change to.

In dev, I have tried this where data does and does not exist. Where there is no data this works fine.

ALTER TABLE [rpt].ReportLessonCompetency WITH CHECK
ADD CONSTRAINT [FK_Grade_TraineeGrade_Id]
FOREIGN KEY (Grade) REFERENCES [rpt].TraineeGrade(Id)
Run Code Online (Sandbox Code Playgroud)

Where there is data I get the following error

The ALTER TABLE statement conflicted with the FOREIGN KEY …

foreign-key sql-server

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

foreign-key ×1

sql-server ×1