
DELETE FROM VCLib.T_USER_COLUMNS
WHERE UserContextID IN (
    SELECT UserContextID
    FROM VCLib.T_USER_CONTEXTS 
    WHERE EntityID = (
        SELECT EntityID 
        FROM VCLib.T_ENTITIES 
        WHERE EntName = 'EKB_HOSPITALIZATION_REFERRAL' AND [Schema] = 'AKUZ'
))
GO

DELETE FROM VCLib.T_USER_CONTEXTS 
WHERE EntityID = (
    SELECT EntityID 
    FROM VCLib.T_ENTITIES 
    WHERE EntName = 'EKB_HOSPITALIZATION_REFERRAL' AND [Schema] = 'AKUZ'
)
GO

DELETE FROM VCLib.T_ENTITIES_ATTRIBUTES 
WHERE EntityID = (
    SELECT EntityID 
    FROM VCLib.T_ENTITIES 
    WHERE EntName = 'EKB_HOSPITALIZATION_REFERRAL' AND [Schema] = 'AKUZ'
)
GO

DELETE FROM EHR.T_EHR_REFERENCE
WHERE Entities = (
    SELECT Entities
    FROM VCLib.T_ENTITIES 
    WHERE EntName = 'EKB_HOSPITALIZATION_REFERRAL' AND [Schema] = 'AKUZ'
)
GO

DELETE FROM VCLib.T_ENTITIES 
WHERE EntName = 'EKB_HOSPITALIZATION_REFERRAL' AND [Schema] = 'AKUZ'
GO

DROP TABLE AKUZ.T_EKB_HOSPITALIZATION_REFERRAL
GO