DO $$
BEGIN
	IF NOT EXISTS (select * from information_schema.columns where table_name='t_card_note' and column_name='emdrbaseobjectent') THEN

		ALTER TABLE AKUZ.T_CARD_NOTE ADD COLUMN IF NOT EXISTS "emdrbaseobjectent" integer NULL;
		ALTER TABLE AKUZ.T_CARD_NOTE ADD CONSTRAINT FK_T_ENTITIES_T_CARD_NOTE_EmdrBaseObjectEnt
		FOREIGN KEY("emdrbaseobjectent") REFERENCES VCLib.T_ENTITIES (EntityID);
	END IF;
END;
$$;