do $$
declare _EntID integer;
begin
	_EntID := (select e.EntityID from VCLib.T_ENTITIES e where e.EntName = 'FRVICH_PATIENT_COMMON' and e.Schema = 'AKUZ');

	delete from VCLib.T_USER_COLUMNS cl
	where exists (select * from VCLib.T_USER_CONTEXTS cx where cx.UserContextID = cl.UserContextID and cx.EntityID = _EntID);

	delete from EHR.T_EHR_REFERENCE where Entities = _EntID;
	delete from VCLib.T_USER_CONTEXTS where EntityID = _EntID;
	delete from VCLib.T_ENTITIES_ATTRIBUTES where EntityID = _EntID;
	delete from VCLib.T_ENTITIES where EntityID = _EntID;
end;
$$ language plpgsql;