Skip to Main Content

SQLcl

Compatible data type add FK

Michelle KrammNov 26 2021

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 );

image.png

Comments
Post Details
Added on Nov 26 2021
2 comments
121 views