1. 程式人生 > >購物系統(2)-資料庫設計

購物系統(2)-資料庫設計

在這裡插入圖片描述`-- MySQL Script generated by MySQL Workbench
– 2018年12月01日 星期六 21時48分31秒
– Model: New Model Version: 1.0
– MySQL Workbench Forward Engineering

SET @[email protected]@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @[email protected]@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @[email protected]

@SQL_MODE, SQL_MODE=‘ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION’;


– Schema mydb


DROP SCHEMA IF EXISTS mydb ;


– Schema mydb


CREATE SCHEMA IF NOT EXISTS mydb ;
USE mydb ;


– Table mydb.user_info


DROP TABLE IF EXISTS mydb

.user_info ;

CREATE TABLE IF NOT EXISTS mydb.user_info (
user_id INT NOT NULL,
user_name VARCHAR(45) NULL,
user_sex VARCHAR(10) NULL,
user_phone VARCHAR(11) NULL,
user_pw VARCHAR(100) NULL,
user_state VARCHAR(5) NULL,
PRIMARY KEY (user_id))
ENGINE = InnoDB
COMMENT = ‘使用者資訊\n’;


– Table mydb.goods-info


DROP TABLE IF EXISTS mydb.goods-info ;

CREATE TABLE IF NOT EXISTS mydb.goods-info (
goods-id INT NOT NULL,
goods-name VARCHAR(200) NULL,
goods-price DOUBLE NULL,
goods-url VARCHAR(1000) NULL,
goods-desc VARCHAR(2000) NULL,
goods-state VARCHAR(10) NULL,
PRIMARY KEY (goods-id))
ENGINE = InnoDB;


– Table mydb.consignee_management


DROP TABLE IF EXISTS mydb.consignee_management ;

CREATE TABLE IF NOT EXISTS mydb.consignee_management (
consignee_id INT NOT NULL,
consignee_name VARCHAR(50) NULL,
consignee_address VARCHAR(1000) NULL,
consignee_code VARCHAR(10) NULL,
cinsignee_phone VARCHAR(11) NULL,
user_info_user_id INT NOT NULL,
PRIMARY KEY (consignee_id),
INDEX fk_Consignee_management_user_info1_idx (user_info_user_id ASC),
CONSTRAINT fk_Consignee_management_user_info1
FOREIGN KEY (user_info_user_id)
REFERENCES mydb.user_info (user_id)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;


– Table mydb.order_management


DROP TABLE IF EXISTS mydb.order_management ;

CREATE TABLE IF NOT EXISTS mydb.order_management (
order_id INT NOT NULL,
order_time DATETIME NULL,
order_total DOUBLE NULL,
order_state VARCHAR(10) NULL,
user_info_user_id INT NOT NULL,
PRIMARY KEY (order_id),
INDEX fk_order_management_user_info1_idx (user_info_user_id ASC),
CONSTRAINT fk_order_management_user_info1
FOREIGN KEY (user_info_user_id)
REFERENCES mydb.user_info (user_id)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;


– Table mydb.order_detail


DROP TABLE IF EXISTS mydb.order_detail ;

CREATE TABLE IF NOT EXISTS mydb.order_detail (
order_detail_id INT NOT NULL,
order_number INT NULL,
order_price DOUBLE NULL,
order_management_order_id INT NOT NULL,
goods-info_goods-id INT NOT NULL,
PRIMARY KEY (order_detail_id),
INDEX fk_order_detail_order_management1_idx (order_management_order_id ASC) ,
INDEX fk_order_detail_goods-info1_idx (goods-info_goods-id ASC) ,
CONSTRAINT fk_order_detail_order_management1
FOREIGN KEY (order_management_order_id)
REFERENCES mydb.order_management (order_id)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT fk_order_detail_goods-info1
FOREIGN KEY (goods-info_goods-id)
REFERENCES mydb.goods-info (goods-id)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;

SET [email protected]_SQL_MODE;
SET [email protected]_FOREIGN_KEY_CHECKS;
SET [email protected]_UNIQUE_CHECKS;
`