Wkyp Wkyp - 6 months ago 12
MySQL Question

Creating database in MYSQL throws this mistakes

set foreign_key_checks=0

CREATE TABLE product(
id INT(10) NOT NULL AUTO_INCREMENT,
name varchar(100),
category_id INT,
PRIMARY KEY (id),
FOREIGN KEY (category_id) REFERENCES category (id) on update cascade on delete cascade);

CREATE TABLE customer(
id INT(10) NOT NULL AUTO_INCREMENT,
name varchar(50),
email varchar(100),
password varchar(25),
PRIMARY KEY (id));

CREATE TABLE purchase(
id INT NOT NULL AUTO_INCREMENT,
user_account_id INT(10),
product id INT(10),
PRIMARY KEY (id),
FOREIGN KEY (user_account_id) REFERENCES customer(id));


CREATE TABLE category(
id INT(10) NOT NULL AUTO_INCREMENT,
kategorija VARCHAR(50),
PRIMARY KEY (id));


CREATE TABLE purchase_item(
purchase_id INT(10),
product_id INT(10),
number_of_items INT(10),
total_price DECIMAL,
FOREIGN KEY (puchase_id) REFERENCES purchase(id),
FOREIGN KEY (product_id) REFERENCES product(id));


First Mistake:

enter image description here

Second Mistake:

enter image description here

Answer

Main errors are due to following lines:

Error 1:

set foreign_key_checks=0

Above line missed statement termination symbol semi-colon ( ; ).

Error 2:

product id INT(10),

Above line is missing underscore between words product and id.
It should be product_id.

Make above changes and your sql script should be working.

Comments