3
respostas

Error Sintax SQL table resposta

Estou tomando erro de sitax ao criar o arquivo da tabela resposta, não estou conseguindo identificar o motivo, já deletei e refiz varias vezes poderia me ajudar?

ERROR:

SQL State : 42001 Error Code : 42001 Message : Syntax error in SQL statement "create table resposta(\000a id bigint not null,\000a mensagem varchar(300) not null,\000a data_criacao datetime not null,\000a topico_id bigint not null,\000a autor_id bigint not null,\000a solucao int* not null,\000a primary key(id),\000a foreign key topico_id references topico(id),\000a foreign key autor_id references usuario(id)\000a)"; expected "ARRAY, INVISIBLE, VISIBLE, NOT, NULL, AS, DEFAULT, GENERATED, ON, NOT, NULL, AUTO_INCREMENT, DEFAULT, NULL_TO_DEFAULT, SEQUENCE, SELECTIVITY, COMMENT, CONSTRAINT, COMMENT, PRIMARY, UNIQUE, NOT, NULL, CHECK, REFERENCES, AUTO_INCREMENT, ,, )"; SQL statement: create table resposta( id bigint not null, mensagem varchar(300) not null, data_criacao datetime not null, topico_id bigint not null, autor_id bigint not null, solucao int(1) not null, primary key(id), foreign key topico_id references topico(id), foreign key autor_id references usuario(id) ) [42001-212] Location : db/migration/V4__create_table_resposta.sql (/home/sillasroberto/Documentos/Estudos Devtools/forum/target/classes/db/migration/V4__create_table_resposta.sql) Line : 1

3 respostas

Oi Sérgio,

Na parte dos foreign key o nome da coluna precisa estar entre parentesis:

foreign key topico_id references topico(id), foreign key autor_id references usuario(id)

Altere para:

foreign key (topico_id) references topico(id), foreign key (autor_id) references usuario(id)

Continuou reclamando da sintax.

Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "create table resposta(\000a id bigint not null,\000a mensagem varchar(300) not null,\000a data_criacao datetime not null,\000a topico_id bigint not null,\000a autor_id bigint not null,\000a solucao int* not null,\000a primary key(id),\000a foreign key (topico_id) references topico(id),\000a foreign key (autor_id) references usuario(id)\000a)"; expected "ARRAY, INVISIBLE, VISIBLE, NOT, NULL, AS, DEFAULT, GENERATED, ON, NOT, NULL, AUTO_INCREMENT, DEFAULT, NULL_TO_DEFAULT, SEQUENCE, SELECTIVITY, COMMENT, CONSTRAINT, COMMENT, PRIMARY, UNIQUE, NOT, NULL, CHECK, REFERENCES, AUTO_INCREMENT, ,, )"; SQL statement: create table resposta( id bigint not null, mensagem varchar(300) not null, data_criacao datetime not null, topico_id bigint not null, autor_id bigint not null, solucao int(1) not null, primary key(id), foreign key (topico_id) references topico(id), foreign key (autor_id) references usuario(id)

Nessa mensagem de erro que você mandou o comando sql ta aparecendo com uns caracteres estranhos: \000a e int* Dá uma conferida no arquivo sql se está com esse problema de caracteres ou acentuação.

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software