商店表的设计

– 商店表的设计
#现有一个商店的数据库shop_db,记录客户及其购物情况,有下面三个表组成:
#商品goods(商品号 goods_id,商品名 goods_name, 单价 unitprice,商品类别 category,供应商 provider)
#客户Customer(客户号 Customer_id,姓名 name,住址address,电子邮件email,性别sex,身份证 crad_id)

#购买 purchase

(购买订单号order_id,客户号customer_id,商品号goods_id,购买数量nums)

-- 创建数据库

CREATE DATABASE shop_db;

USE shop_db;
#商品goods(商品号 goods_id,商品名  goods_name, 单价 unitprice,商品类别 category,供应商 provider)

CREATE TABLE goods(
	goods_id  INT PRIMARY KEY ,
	goods_name VARCHAR(32)  NOT NULL DEFAULT "",
	unitprice  DOUBLE CHECK(sex  BETWEEN 1.0 AND 9999.99),
	category VARCHAR(32)  NOT NULL DEFAULT "",
	provider VARCHAR(32)  DEFAULT ""
);
#客户Customer(客户号  Customer_id,姓名 name,住址address,电子邮件email,性别sex,身份证 crad_id)
CREATE TABLE Customer( 
 Customer_id INT PRIMARY KEY,
NAME VARCHAR(32) NOT NULL,
address VARCHAR(32),
email  VARCHAR(32) UNIQUE,
sex CHAR(1) CHECK (sex IN('男','女')) ,
crad_id VARCHAR(18) 
);

#购买 purchase (购买订单号order_id,客户号customer_id,商品号goods_id,购买数量nums)

CREATE TABLE  purchase(
order_id  INT PRIMARY KEY,
customer_id  INT,
FOREIGN KEY (customer_id) REFERENCES  Customer(customer_id),
goods_id INT,
FOREIGN KEY (goods_id) REFERENCES  goods(goods_id),
nums INT);
上一篇:python-alipay-sdk


下一篇:结算到提交订单