The DELETE statement conflicted with the REFERENCE constraint

Page是主表,主键是pageid;UserGroupPage表中的PageID字段是Page表里的数据。 

 https://www.codeproject.com/Questions/677277/I-am-getting-error-while-delete-entry

You are trying to Delete the record from a Table which has a reference in another Table.

Here REFERENCE constraint is "FK_User_History_Tbl_Customer".

Tables are User_History and Tbl_Customer.
UserId column is referenced by Tbl_Customer Table.

When you try to delete a row from User_History Table, it comes to know that the same row has some related row in Tbl_Customer Table.

So, you need to delete from Tbl_Customer Table first and then delete from Table User_History.

If you want to delete a row, then you have to execute the following two queries in sequence.

DELETE FROM Tbl_Customer
WHERE UserId = [[[UserIdToDelete]]];

DELETE FROM User_History
WHERE UserId = [[[UserIdToDelete]]]

尝试筛选了一下数据,居然有记录。本地的开发环境是没有记录的

SELECT *
FROM   dbo.tba_ugp_UserGroupPage AS c
WHERE  EXISTS (   SELECT a.PageID
                  FROM   dbo.tbx_pag_Page AS a
                         INNER JOIN dbo.tbx_mod_Module AS b ON a.ModuleID = b.ModuleID
                  WHERE  b.PhysicalModuleID IN ( 16, 19 )
                         AND a.PageID = c.PageID );
原文地址:https://www.cnblogs.com/chucklu/p/10528825.html