SQL SCRIPT WITH ERROR

0

For the sake of curiosity I got a story from my second half of ADS and this is a SQL script based on 3 tables: ALUNO , CLASSE , MATRICULA .

I made the script according to the statement, but my script does not execute, the following error appears

  

ORA-00907: missing right parenthesis

Follow my script 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 link to test the script.

    
asked by anonymous 21.12.2018 / 14:21

1 answer

2

Hello,

There are two errors in the script:

1 - A comma is missing between each constraint declaration in the creation of the license plate.

2 - In the table, in the fk_Classe constraint, it is referencing the Student table, but in fact the one who owns this column is the 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)
);
    
21.12.2018 / 14:44