mysql syntax error

Asked

Viewed 29 times

-2

I am running the following script for database creation:

create database jogos;
use jogos;
create table jogo(
    codigojogo int auto_increment primary key,
    nomejogo varchar(40) not null
);

create table nivel(
    codigonivel int auto_increment primary key,
    dificuldade varchar(40) not null
);
create table jogonivel(
    codigon int,
    codigoj int,
    primary key(codigon, codigoj),
    constraint fk_codnivel foreign key (codigon) references nivel(codigonivel),
    constraint fk_codjogo foreign key (codigoj) references jogo(codigojogo),

);
insert into nivel (dificuldade) values ('facil');
insert into nivel (dificuldade) values ('medio');
insert into nivel (dificuldade) values ('dificil');

When I run it, it error on line 8 near ')' but I don’t know what might be... I’ve reworked the line, changed values but nothing.

1 answer

1


There was a comma left at the end of the last line of the playable table create.

The correct syntax should be this one below:

create table jogonivel (
    codigon int,
    codigoj int,
    primary key(codigon, codigoj),
    constraint fk_codnivel foreign key (codigon) references nivel(codigonivel),
    constraint fk_codjogo foreign key (codigoj) references jogo(codigojogo)
);

Browser other questions tagged

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