我已经使用Aasim Abdullah's存储过程动态生成用于删除子表的代码,基于具有特定过滤条件的父级。但我得到的输出不正确(查询1)。我想在查询2中提到输出。
- [Patient]是Parent表,[Case]是子表,[ChartInstanceCase]是grand child - 当我删除一个大子表时,它应首先链接到子表,然后是父
查询1
DELETE Top(100000) FROM [dbo].[ChartInstanceCase]
FROM [dbo].[Patient]
INNER JOIN [dbo].[Case] ON [Patient].[PatientID] = [Case].[PatientID]
INNER JOIN [dbo].[ChartInstanceCase] ON [ChartInstanceCase].[CaseId] = [Case].[CaseID]
WHERE [Patient].PracticeID = '55';
查询2
DELETE Top(100000) [dbo].[ChartInstanceCase]
FROM [dbo].[ChartInstanceCase]
INNER JOIN [dbo].[Case] ON [ChartInstanceCase].[CaseId] = [Case].[CaseID]
INNER JOIN [dbo].[Patient] ON [Patient].[PatientID] = [Case].[PatientID]
WHERE [Patient].PracticeID = '55';
请告诉我如何修改SP dbo.uspCascadeDelete
以获取输出为查询2?