DO $$
BEGIN
    IF NOT EXISTS (
        SELECT 1 
        FROM information_schema.tables 
        WHERE table_schema = 'EHR' 
        AND table_name = 'T_EHR_RUS_UVUJ3PNOPM'
    ) THEN

	-- Tables

    /***** Object:  Table EHR.T_EHR_RUS_UVUJ3PNOPM *****/
    CREATE TABLE EHR.T_EHR_RUS_UVUJ3PNOPM
    (
        "ehrrusid" integer NOT NULL,
        "idehr" integer NULL,
        "nameehr" varchar(2048) NULL,
        "ehrrusrefbooks" integer NOT NULL
    );

    -- Alters

    ALTER TABLE EHR.T_EHR_RUS_UVUJ3PNOPM ADD CONSTRAINT PK_T_EHR_RUS_UVUJ3PNOPM
    PRIMARY KEY (EhrRusID);

    ALTER TABLE EHR.T_EHR_RUS_UVUJ3PNOPM ADD CONSTRAINT FK_T_EHR_RUS_REF_BOOKS_T_EHR_RUS_UVUJ3PNOPM_EhrRusRefBooks
    FOREIGN KEY("ehrrusrefbooks") REFERENCES EHR.T_EHR_RUS_REF_BOOKS (EhrRusRefBooksID);

    END IF;
END $$;