0

I have to write some Create table statements in SQL for a school assignment, after that i have to load the SQL file in AnySQL Maestro, when I execute the script it gives an SYNTAX error on the 3rd CREATE TABLE statement(create table BESTELLING) and i can't figure out what i did wrong. I hope someone can help me.

create table INKOPER(
inkoperID   char (2),
naam        varchar(128),

constraint pk_inkoper
primary key (inkoperID)
); go

create table ARTIKEL(
artikelnr       varchar(5),
omschrijving    varchar(255),
prijs           decimal(8,2),

constraint pk_artikel
    primary key (artikelnr)
);go

create table LEVERANCIER(
leveranciernr       varchar(3),
naam                varchar(20),
adres               varchar(50),
woonplaats          varchar(20),
telefoon            char(11),

constraint pk_leverancier
    primary key (leveranciernr)
); go

create table BESTELLING(
bestelnr        integer,
leveranciernr   integer is null,
inkoperID       char(2),
besteldatum     date,
leverdatum      date,

constraint pk_bestelling
    primary key (bestelnr),
constraint fk_bestelling_leverancier
    foregin key (leveranciernr)
    references leverancier(leveranciernr)
constraint fk_bestelling_inkoper
    foregin key (inkoperID)
    references inkoper(inkoperID)   
); go

create table BESTELREGEL(
bestelnr        integer,
artikelnr       varchar(5),
aantal          integer,

constraint pk_bestelling_artikel
    primary key (bestelnr,artikelnr),
constraint fk_bestelling_bestelregel
    foregin key (bestelnr)
    references bestelling(bestelnr)
constraint fk_artikel_bestelregel
    foreign key (artikelnr)
    references artikel(artikelnr)
); go
2
  • 1
    Why do you have a comma on the first constraint for each table and no commas on the subsequent ones? Should there be a comma on the after the first primary key constraint? I'm not familiar with this flavor of SQL, but that in general doesn't seem right. Commented Sep 1, 2015 at 17:27
  • Thats how it was explained to me today at school, only a comma after the constraint for the primary key, but I also thought it is a bit odd, i changed it but it gave the same error Commented Sep 1, 2015 at 18:00

2 Answers 2

1

The error is in the line:

leveranciernr   integer is null,

this is not standard SQL. If you want that the attribute can assume null values, then you should write:

leveranciernr   integer not null,

By default in SQL all the attributes can have null values unless specified not null.

Sign up to request clarification or add additional context in comments.

1 Comment

I totally looked over that... i changed it but now it gives the error Syntax error in field definition on the same line
0

I see you deleted your comments FutbolFan, I still wanted to give you an update, I removed the foreign key constraints and now i got the error: There are one or more errors occurred while processing command, I start to think Any SQL is playing with me.... Anyway i had to assign my assignment before midnight, so is think i'm just gonna upload my sql script and i hope my teacher can explain what went wrong, Thanks for your input and if i fixed my problem tomorrow, then i will post the answer here!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.