spDelete_NetAccount
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@PKID | int | IN | |
@CurrentUsersID | int | IN |
Definition
Copy
CREATE PROCEDURE [dbo].[spDelete_NetAccount]
(
@PKID int,
@CurrentUsersID int
)
AS
BEGIN
if exists(SELECT ID from [NetGroup] where NetAccountID=@PKID)
begin
raiserror ('Unable to delete Account. It is the owner of one or more Groups. ',16,1)
return
end
--- 1 is the special reserved NetAccountID for the DeletedUser
--- Messages owned by this guy is deleted through cascade
--- NetGroupRelation is deleted through cascade
--Update messages he sent to others
UPDATE [Message] SET SenderID = 1 WHERE SenderID = @PKID
--Update messages sent to him but owned by the other guy
UPDATE [Message] SET RecipientID = 1 WHERE RecipientID = @PKID
--Delete NetAccountRelations
----- The other deletes are done with cascading foreign key constraints,
----- but because this table has 2 columns referencing NetAccountID it thinks it might by cyclicle
DELETE FROM NetAccountRelation WHERE NetAccountID = @PKID OR RelationAccountID = @PKID
DELETE FROM NetAccount WHERE ID = @PKID
END