0
I’m making a program where the user can register and search for questions. Each question has a domain (e.g., law, psychology), various themes, a difficulty, the text of the question and the answer. until now my code registers and searches the questions, but now I will implement it to a database, but I am very lay in the subject and I’m having problems creating the tables I always come across several errors and now I’m not able to create this sequence of tables:
I’m trying to create with this code:
CREATE TABLE tab_dominio (id_dominio SERIAL NOT NULL PRIMARY KEY, dominio varchar (50))
CREATE TABLE dificuldade (dificuldade int)
CREATE TABLE tab_questoes (id_questao SERIAL NOT NULL PRIMARY KEY, dominio varchar(50) FOREIGN KEY references tab_dominio(dominio), dificuldade FOREIGN KEY references dificuldade(dificuldade), pergunta varchar(250), resposta varchar(250))
CREATE TABLE tab_temas (id_tema SERIAL PRIMARY KEY NOT NULL, dominio varchar(50) FOREIGN KEY references tab_dominio(dominio), tema varchar(50))
CREATE TABLE questaotema (id_questao int FOREIGN KEY references tab_questoes(id_questao), id_tema FOREIGN KEY references tab_temas(tema))
But I’m getting the bug:
ERROR: syntax error at or near "FOREIGN" LINE 1: ... SERIAL NOT NULL PRIMARY KEY, dominio varchar(50) FOREIGN KE..
If I delete where it says there is error it keeps showing more and more errors and in the end I can’t create my table, I’m caught in it.
really forgot to put the relationship between tables table_questoes and Themes in the drawing, I apologize, I tried with the changes you spoke but remained presenting the same error that I put above, I have made several changes in the order of writing but always points error in the first "FOREIGN" you find
– J. Weslley
For typo had a wrong field name, d_domain instead of id_domain. Fixed.
– anonimo