2

Ao criar essa tabela no postgre sql recebo essa mensagem de erro

Criacao da tabela tipo_agendamento_escritorio

create table tipo_agendamento_escritorio(
    id int8 not null,
    primary key (id),
    tipo_agendamento_id int8 not null,
    constraint foreign key (tipo_agendamento_id) REFERENCES tipo_agendamento (id),
    prazocomum int8 not null,
    prazotrabalhista int8 not null,
    tempoconfeccao int8 not null
);
create sequence tipo_agendamento_escritorio_id_seq;

Recebo a mensagem de erro:

SQL Error [42601]: ERROR: syntax error at or near "foreign"

1
  • "Acho" que tá sobrando um constraint ali. Ela seria usada caso estivesse adicionando a chave estrangeira posterior à criação da tabela (query distinta).
    – LipESprY
    20/03/2019 às 22:42

2 Respostas 2

1

Simplifique:

create table tipo_agendamento_escritorio(
    id int8 not null,
    primary key (id),
    tipo_agendamento_id int8 not null REFERENCES tipo_agendamento (id),
    prazocomum int8 not null,
    prazotrabalhista int8 not null,
    tempoconfeccao int8 not null
);
create sequence tipo_agendamento_escritorio_id_seq;

ou, se quiser declarar separadamente (table constraint), coloque um nome da constraint após o termo CONSTRAINT:

constraint um_nome_qualquer foreign key (tipo_agendamento_id) REFERENCES tipo_agendamento (id)
1

Faltou o nome da constraint:

...
constraint nome_constraint foreign_key (tipo_agendamento_id) REFERENCES tipo_agendamento (id),
...

Ou inibir a palavra constraint

...
foreign_key (tipo_agendamento_id) REFERENCES tipo_agendamento (id),
...

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .