Hi,

I can create all tables but order table. What is wrong, is it foreign key?

CREATE TABLE customer(
customerId INT(10) NOT NULL AUTO_INCREMENT, 
customerName VARCHAR(10),
customerSurname VARCHAR(10),
customerAddress VARCHAR(10),
PRIMARY KEY (customerId));

CREATE TABLE order(
orderId INT(10) NOT NULL AUTO_INCREMENT, 
customerId INT(10),
PRIMARY KEY (orderId),
FOREIGN KEY (customerId) REFERENCES customer(customerId));

CREATE TABLE orderDetail(
orderDate DATE,
orderId INT(10), 
productId INT(10),
FOREIGN KEY (orderId) REFERENCES order(orderId),
FOREIGN KEY (productId) REFERENCES product(productId));

CREATE TABLE product(
productId INT(10) NOT NULL AUTO_INCREMENT, 
productName VARCHAR(10),
PRIMARY KEY (productId));

CREATE TABLE stock(
stock INT(10), 
productId INT(10),
FOREIGN KEY (productId) REFERENCES product(productId));

Thanks

Recommended Answers

All 2 Replies

"order" is a reserved word so you need to quote it if you're going to use it for a table name. See here for details.

thanks, it works with "orders".

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.