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

	-- Tables

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

    -- Alters

    ALTER TABLE EHR.T_EHR_RUS_NPN56FUJV4 ADD CONSTRAINT PK_T_EHR_RUS_NPN56FUJV4
    PRIMARY KEY (EhrRusID);

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

    END IF;
END $$;