我正在尝试使用以下存储过程从数据库中删除父记录和子记录:
CREATE PROCEDURE [dbo].[DeleteCompanyPersonAndPhoneNumbers] (
@personId int,
@deleted bit output)
AS
BEGIN
SET NOCOUNT ON;
SET XACT_ABORT ON;
set @deleted = 0
begin transaction
-- delete the phone numbers
delete from PersonalPhoneNumber
where PersonalPhoneNumber.PersonId = @personId
delete from ProfessionalProfile
where ProfessionalProfile.Person_Id = @personId
delete from aspnet_UserProfile
where aspnet_UserProfile.Person_ID = @personId
delete from Accreditation
where Accreditation.Person_ID = @personId
delete from Qualification
where Qualification.Person_ID = @personId
delete from PERSON where Person_ID = @personId
set @deleted = 1
commit transaction
END
我已将外键强制关闭。当运行 sp 它只删除父记录。
我在 SP 中做错了什么?
谢谢