Search code examples
sqloracle-databasecreate-table

Run sql command line, issue. Creating tables


I'm trying to create a table in run sql command line of oracle database 11 xe.

My problem is when I finish typing my code:

create table vigilantes(
idVigilantes integer(3) not null,
nombre varchar(100) not null,
paterno varchar(100) not null,
materno varchar(100) not null,
id_caseta integer(3) null,
id_turno integer(3) null,
edad integer(3) not null,
id_genero integer(1) not null,
idEmpresa integer(3) not null,
constraint pk_idVigilantes PRIMARY KEY (idVigilantes)
constraint fk_id_caseta FOREIGN KEY (id_caseta)
references Caseta(id_caseta)
constraint fk_id_turno FOREIGN KEY(id_turno)
references Turno(id_turno)
constraint fk_id_genero FOREIGN KEY(id_genero)
references Generos(id_genero)
constraint fk_idEmpresa FOREIGN KEY(idEmpresa)
references Empresa(idEmpresa)
);

I get "ORA-00907: missing right parenthesis" issue. I read that this is often caused by not defining a value. e.g:

create table vigilantes(
idVigilantes integer not null,
.......

But still no solution here. Any help or clue will be a lot of help.


Solution

  • You are missing comma after constraints. Also, integer has no precision.

    create table vigilantes (
        idVigilantes integer not null,
        nombre varchar(100) not null,
        paterno varchar(100) not null,
        materno varchar(100) not null,
        id_caseta integer null,
        id_turno integer null,
        edad integer not null,
        id_genero integer not null,
        idEmpresa integer not null,
        constraint pk_idVigilantes primary key (idVigilantes),
        constraint fk_id_caseta foreign key (id_caseta) references Caseta(id_caseta),
        constraint fk_id_turno foreign key (id_turno) references Turno(id_turno),
        constraint fk_id_genero foreign key (id_genero) references Generos(id_genero),
        constraint fk_idEmpresa foreign key (idEmpresa) references Empresa(idEmpresa)
        );
    

    If you must define precision, use number datatype:

    create table vigilantes (
        idVigilantes number(3, 0) not null,
        nombre varchar(100) not null,
        paterno varchar(100) not null,
        materno varchar(100) not null,
        id_caseta number(3, 0) null,
        id_turno number(3, 0) null,
        edad number(3, 0) not null,
        id_genero number(1, 0) not null,
        idEmpresa number(3, 0) not null,
        constraint pk_idVigilantes primary key (idVigilantes),
        constraint fk_id_caseta foreign key (id_caseta) references Caseta(id_caseta),
        constraint fk_id_turno foreign key (id_turno) references Turno(id_turno),
        constraint fk_id_genero foreign key (id_genero) references Generos(id_genero),
        constraint fk_idEmpresa foreign key (idEmpresa) references Empresa(idEmpresa)
        );