Jump to content

[Resolvido] There are no primary or candidate keys in the referenced table("questoes")


Leudassdf

Recommended Posts

Boas pessoal,

Eu estou a tentar criar estas tabelas. no entanto quando é para criar a tabela respostas obtenho o erro:There are no primary or candidate keys in the referenced table("questoes").

Alguem sabe como resolver?

Cumprimentos

Create table Questoes(
NQuestao decimal Primary key,
CotacaoTotal decimal,
Tipo varchar(20),

Id_Teste int,

FOREIGN KEY (Id_Teste) REFERENCES Teste(Id_Teste));

Create table Respostas(
N_Processo varchar(10),
Classificacao decimal,
Tipo varchar(20),
NQuestao decimal,
FOREIGN KEY (NQuestao) REFERENCES teste(NQuestao),
FOREIGN KEY (NQuestao) REFERENCES Questoes(NQuestao),
FOREIGN KEY (N_Processo) REFERENCES Alunos(N_Processo));

Create table Teste(
Id_Teste int identity(1,1) primary key,
Descricao varchar(50),
Tema_Modulo varchar(50),
CotacaoTotal decimal,
Data DATE DEFAULT GETDATE(),

CodTruma int,
N_Prof_Processo varchar(10),

CodDisciplina int,
FOREIGN KEY (N_Prof_Processo) REFERENCES Professor (N_Prof_Processo),
FOREIGN KEY (CodTruma) REFERENCES Turma (CodTruma),
FOREIGN KEY (CodDisciplina) REFERENCES Disciplina (CodDisciplina));
Edited by Leudassdf
Link to comment
Share on other sites

resolvido.

ficou assim:

Create table Questoes(
NQuestao decimal ,
CotacaoTotal decimal,
Tipo varchar(20),

Id_Teste int,
primary key(nquestao,id_teste),
FOREIGN KEY (Id_Teste) REFERENCES Teste(Id_Teste));


Create table Respostas(
N_Processo varchar(10),
Classificacao decimal,
Tipo varchar(20),
id_teste int,

NQuestao decimal,

FOREIGN KEY (NQuestao,id_teste) REFERENCES Questoes(NQuestao,id_teste),
FOREIGN KEY (N_Processo) REFERENCES Alunos(N_Processo));
  • Vote 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.