-- goods
CREATE TABLE goods
(
goodsID NVARCHAR(50) PRIMARY KEY,
goodsNAME NVARCHAR(80) NOT NULL,
unitprice NUMERIC(10,2) CHECK (unitprice >0 ),
category NVARCHAR(3) CHECK(category IN ('食物','日用品')),
provider NVARCHAR(50)
);
-- customer
CREATE TABLE customer
(
customerID NVARCHAR(50) PRIMARY KEY,
customerName NVARCHAR(50) NOT NULL,
address NVARCHAR(100),
email NVARCHAR(100) UNIQUE,
gentle NCHAR(1) CHECK(gentle IN ('男','女')),
cardID VARCHAR(18)
);-- purchaseCREATE TABLE purchase
(
customerID NVARCHAR(50) FOREIGN KEY REFERENCES customer(customerID),
goodsID NVARCHAR(80) FOREIGN KEY REFERENCES goods(goodsID),
nums INT CHECK (nums>0)
);最后一个表添加了外键,但是在My Sql中运行会报错:
Error Code : 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'foreign key references customer(customerID),
goodsID NVARCHAR(80) FOREIGN KEY RE' at line 3