On January 27th, this site will be read-only as we migrate to Oracle Forums for an improved community experience. You will not be able to initiate activity until January 30th, when you will be able to use this site as normal.

    Forum Stats

  • 3,889,556 Users
  • 2,269,760 Discussions
  • 7,916,781 Comments

Discussions

Compatible data type add FK

Michelle Kramm
Michelle Kramm Member Posts: 18 Green Ribbon

Hi

I'm trying to create the tables below, and it's time to create the FK, I'm getting a error below. I didn't get what may be wrong and why it's not compatible data type.

CREATE TABLE t_agendamento_exames (

  cd_agendamento     NUMBER GENERATED BY DEFAULT AS IDENTITY,

  t_consulta_cd_consulta VARCHAR2(30) NOT NULL,

  t_exames_cd_exame   VARCHAR2(30) NOT NULL,

  ds_exame        VARCHAR2(250),

  obs_exames       VARCHAR2(250)

);


ALTER TABLE t_agendamento_exames ADD CONSTRAINT t_agendamento_exames_pk PRIMARY KEY ( cd_agendamento );


CREATE TABLE t_consulta (

  cd_consulta      NUMBER GENERATED BY DEFAULT AS IDENTITY,

  t_medico_cd_medico   VARCHAR2(30) NOT NULL,

  t_paciente_cd_paciente VARCHAR2(30) NOT NULL,

  hr_inicio       TIMESTAMP WITH TIME ZONE NOT NULL,

  hr_termino       TIMESTAMP WITH TIME ZONE NOT NULL,

  dt_hr_consulta     DATE NOT NULL,

  nr_consultorio     VARCHAR2(30),

  ob_observação_consulta VARCHAR2(300)

);


ALTER TABLE t_consulta ADD CONSTRAINT t_consulta_pk PRIMARY KEY ( cd_consulta );


ALTER TABLE t_agendamento_exames

  ADD CONSTRAINT t_agend_ex_t_cons_fk FOREIGN KEY ( t_consulta_cd_consulta )

    REFERENCES t_consulta ( cd_consulta );



Tagged:

Answers