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

	-- Tables

    /***** Object:  Table EHR.T_EHR_RUS_69K8FB73EO *****/
    CREATE TABLE EHR.T_EHR_RUS_69K8FB73EO
    (
        "ehrrusid" integer NOT NULL,
        "idehr" integer NULL,
        "nameehr" varchar(2048) NULL,
        "request" integer NULL,
        "consultation" integer NULL,
        "consultant" integer NULL,
        "doctor" integer NULL,
        "dateout" timestamp NULL,
        "ehrrusrefbooks" integer NOT NULL
    );

    -- Alters

    ALTER TABLE EHR.T_EHR_RUS_69K8FB73EO ADD CONSTRAINT PK_T_EHR_RUS_69K8FB73EO
    PRIMARY KEY (EhrRusID);

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

    END IF;
END $$;