Riic0
Riic0

Reputation: 1

SQL Syntax error on create table

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

Upvotes: 0

Views: 200

Answers (2)

Riic0
Riic0

Reputation: 1

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!

Upvotes: 0

Renzo
Renzo

Reputation: 27444

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.

Upvotes: 1

Related Questions