SQL SCRIPT WITH ERROR

Asked

Viewed 119 times

-1

Out of curiosity I took a report from my second semester of ADS and this course consists in making an SQL script based on 3 tables: ALUNO, CLASSE, MATRICULA.

I made the script according to the statement, but my script does not run, it contains the following error

ORA-00907: Missing right parenthesis

Follows my script down below:

Create Table Aluno(
Nr_Rgm number(8),
Nm_Nome varchar(40),
Nm_Mae varchar(40),
Dt_Nascimento date,
Id_sexo char(1),
CONSTRAINT Rgm_pk PRIMARY KEY (Nr_Rgm)
);

Create Table Classe(
Cd_Classe number(8),
Nr_AnoLetivo number(4),
Nr_Serie number(2),
Sg_Turma varchar(2),
Cd_Escola number(6),
Cd_Grau number(2),
Cd_Periodo number (2),
CONSTRAINT Classe_pk PRIMARY KEY (Cd_Classe)
);

Create Table Matricula(
Nr_Rgm number(8) ,
Dt_Matricula date,
Cd_Classe number(8),
CONSTRAINT fk_Rgm
FOREIGN KEY (Nr_Rgm)
REFERENCES Aluno(Nr_Rgm)
CONSTRAINT fk_Classe
FOREIGN KEY (Cd_Classe)
REFERENCES Aluno(Cd_Classe)
);

I’m using the http://www.sqlfiddle.com to test the script.

1 answer

2


Hello,

In the script there are two errors:

1 - A comma is missing between each Constraint statement in the registration table creation.

2 - In the registration table, in the Constraint fk_Classe, he is referencing the table Pupil, but in fact who owns this column is the table Class

The correct script would look like this:

Create Table Aluno( 
Nr_Rgm number(8),
Nm_Nome varchar(40),
Nm_Mae varchar(40),
Dt_Nascimento date,
Id_sexo char(1),
CONSTRAINT Rgm_pk PRIMARY KEY (Nr_Rgm)
);

Create Table Classe(
Cd_Classe number(8),
Nr_AnoLetivo number(4),
Nr_Serie number(2),
Sg_Turma varchar(2),
Cd_Escola number(6),
Cd_Grau number(2),
Cd_Periodo number (2),
CONSTRAINT Classe_pk PRIMARY KEY (Cd_Classe)
);

Create Table Matricula(
Nr_Rgm number(8) ,
Dt_Matricula date,
Cd_Classe number(8),
CONSTRAINT fk_Rgm FOREIGN KEY (Nr_Rgm) REFERENCES Aluno(Nr_Rgm),
CONSTRAINT fk_Classe FOREIGN KEY (Cd_Classe) REFERENCES Classe(Cd_Classe)
);
  • thank you very much, it worked

  • @Wílsantos, if you have solved the problem, mark the answer as accepted ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.