 ALTER TABLE IOEVENTS
 ADD CONSTRAINT ioevents_fk_icustay_id
   FOREIGN KEY (icustay_id)
-  REFERENCES icustayevents(icustay_id);
+  REFERENCES icustays(icustay_id);
 
 -- cgid
 ALTER TABLE IOEVENTS

ALTER TABLE CHARTEVENTS
ADD CONSTRAINT chartevents_fk_icustay_id
  FOREIGN KEY (icustay_id)
  REFERENCES icustayevents(icustay_id);

-------------
--CPTEVENTS--

ALTER TABLE PRESCRIPTIONS
ADD CONSTRAINT prescriptions_fk_icustay_id
  FOREIGN KEY (icustay_id)
  REFERENCES icustays(icustay_id);

------------------
--PROCEDURES_ICD--
