MySQL創建數據庫 easyShopping,包括area表、goods表、customer表、orders表、ordersdetall表、test表

MySQL創建數據庫 easyShopping,包括area表、goods表、customer表、orders表、ordersdetall表、test表

商品表表結構:

字段名

googsID

商品編號

int

主鍵、自動增長

goodsCode

商品編碼

varchar

20

非空

goodsName

商品名

varchar

50

非空

category

商品種類

varchar

20

unitPrice

單價

decimal(8,2)

create table goods(  --商品表
    goodsID int primary key auto_increment, 
    goodsCode varchar(20) unique not null,
    goodsName varchar(50) not null, 
    category varchar(20) default null,
    unitPrice decimal(8,2) default null, 
    areaID int default null,
    saleCount int default null
);

顧客表表結構:

字段名

customerID

客戶編號

int

主鍵、自動增長

loginID

登錄 ID

varchar

20

非空

pwd

密碼

varchar

10

非空

cName

客戶姓名

varchar

20

非空

address

客戶地址

varchar

50

phone

客戶電話

varchar

20

create table customer(  --客戶表
    customerID int primary key auto_increment, 
    loginID varchar(20) unique not null,
    pwd varchar(10) not null,
    cName varchar(20) not null, 
    city varchar(20) default null,
    address varchar(50) default null, 
    phone varchar(20) default null
);

訂單表表結構:

 字段名

說 明

類 型

長 度

約 束

 ordersID

訂單編號

int

主鍵、自動增長

 ordersDate

下單日期

date

非空

 deliveryDate

送達日期

date

 amount

訂單金額

decimal(10,2)

 customerID

客戶編號

int

外鍵,參照 customers 表

完整語法:

/*
Navicat MySQL Data Transfer

Source Server         : demo
Source Server Version : 50622
Source Host           : localhost:3306
Source Database       : easyshopping

Target Server Type    : MYSQL
Target Server Version : 50622
File Encoding         : 65001

Date: 2020-04-01 10:11:51
*/

SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------
-- Table structure for `area`
-- ----------------------------
DROP TABLE IF EXISTS `area`;
CREATE TABLE `area` (
  `areaID` int(11) NOT NULL AUTO_INCREMENT,
  `areaName` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`areaID`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of area
-- ----------------------------
INSERT INTO `area` VALUES ('1', '北京');
INSERT INTO `area` VALUES ('2', '上海');
INSERT INTO `area` VALUES ('3', '深圳');
INSERT INTO `area` VALUES ('4', '廣州');
INSERT INTO `area` VALUES ('5', '南京');

-- ----------------------------
-- Table structure for `customer`
-- ----------------------------
DROP TABLE IF EXISTS `customer`;
CREATE TABLE `customer` (
  `customerID` int(11) NOT NULL AUTO_INCREMENT,
  `loginID` varchar(20) NOT NULL,
  `pwd` varchar(10) NOT NULL,
  `cName` varchar(20) NOT NULL,
  `city` varchar(20) DEFAULT NULL,
  `address` varchar(50) DEFAULT NULL,
  `phone` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`customerID`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of customer
-- ----------------------------
INSERT INTO `customer` VALUES ('2', 'abc222', '222', '王傳華', '北京', '北京市東城區香河園路16 號', '01062111234');
INSERT INTO `customer` VALUES ('3', 'abc333', '333', '張曉靜', '北京', '北京市東城區東直門大街2號', '13501229678');
INSERT INTO `customer` VALUES ('4', 'abc444', '444', '張洪濤', '上海', '上海市徐彙區漕溪路126號', '13818929999');
INSERT INTO `customer` VALUES ('5', 'abc555', '555', '王勇強', '上海', '上海市楊浦區大連路1548', '13671648888');
INSERT INTO `customer` VALUES ('7', 'abc777', '777', '劉亞其', '武漢', '武漢市江岸區洞庭街67', '18674060972');
INSERT INTO `customer` VALUES ('8', 'abc888', '888', '張兆', '武漢', '武漢市洪山區關山一路45號', '18672791254');

-- ----------------------------
-- Table structure for `goods`
-- ----------------------------
DROP TABLE IF EXISTS `goods`;
CREATE TABLE `goods` (
  `goodsID` int(11) NOT NULL AUTO_INCREMENT,
  `goodsCode` varchar(20) DEFAULT NULL,
  `goodsName` varchar(50) DEFAULT NULL,
  `category` varchar(20) DEFAULT NULL,
  `unitPrice` decimal(8,2) DEFAULT NULL,
  `areaID` int(11) DEFAULT NULL,
  `saleCount` int(11) DEFAULT NULL,
  PRIMARY KEY (`goodsID`),
  UNIQUE KEY `goodsName` (`goodsName`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of goods
-- ----------------------------
INSERT INTO `goods` VALUES ('1', '01001', '從心選擇的智慧(李開復)', '書籍', '18.50', '1', '3');
INSERT INTO `goods` VALUES ('2', '01002', 'Java面向對象編程(孫衛琴)', '書籍', '52.60', '2', '6');
INSERT INTO `goods` VALUES ('3', '01003', '漫談中國文化(南懷瑾)', '書籍', '13.00', '3', '13');
INSERT INTO `goods` VALUES ('4', '02001', '艾美特FSW65R-5落地風扇', '生活電器', '199.00', '2', '9');
INSERT INTO `goods` VALUES ('5', '02002', '飛利浦HD3035/05電飯煲', '生活電器', '299.00', '4', '3');
INSERT INTO `goods` VALUES ('6', '02003', '美的FD302電飯煲', '生活電器', '248.00', '2', '7');
INSERT INTO `goods` VALUES ('7', '02004', '格力KYT-2503臺式轉頁扇', '生活電器', '88.00', '4', '8');
INSERT INTO `goods` VALUES ('8', '03001', '尤尼克斯Yonex羽毛球拍', '體育用品', '209.00', '1', '9');
INSERT INTO `goods` VALUES ('9', '03002', 'NIKE籃球BB0361-823', '體育用品', '89.00', '1', '3');
INSERT INTO `goods` VALUES ('10', '03003', '火車頭Train5號PU足球TS5011', '體育用品', '135.00', '3', '6');

-- ----------------------------
-- Table structure for `orders`
-- ----------------------------
DROP TABLE IF EXISTS `orders`;
CREATE TABLE `orders` (
  `ordersID` int(11) NOT NULL AUTO_INCREMENT,
  `ordersDate` date NOT NULL,
  `deliveryDate` date DEFAULT NULL,
  `amount` decimal(10,2) DEFAULT NULL,
  `customerID` int(11) DEFAULT NULL,
  PRIMARY KEY (`ordersID`),
  KEY `fk_orders_customer` (`customerID`),
  CONSTRAINT `fk_orders_customer` FOREIGN KEY (`customerID`) REFERENCES `customer` (`customerID`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=latin1;

-- ----------------------------
-- Records of orders
-- ----------------------------
INSERT INTO `orders` VALUES ('1', '2015-04-10', '2015-04-12', null, '2');
INSERT INTO `orders` VALUES ('2', '2015-05-16', '2015-05-19', null, '5');
INSERT INTO `orders` VALUES ('3', '2015-03-18', '2015-03-19', null, null);
INSERT INTO `orders` VALUES ('4', '2015-04-12', '2015-04-14', null, '3');
INSERT INTO `orders` VALUES ('5', '2015-04-10', '2015-04-12', null, '4');
INSERT INTO `orders` VALUES ('6', '2015-05-16', '2015-05-18', null, '8');
INSERT INTO `orders` VALUES ('7', '2015-03-18', '2015-03-21', null, '7');
INSERT INTO `orders` VALUES ('8', '2015-06-19', '2015-06-20', null, null);
INSERT INTO `orders` VALUES ('9', '2015-04-12', '2015-04-13', '3126.50', '3');
INSERT INTO `orders` VALUES ('10', '2015-05-28', '2015-05-30', null, '5');
INSERT INTO `orders` VALUES ('11', '2015-03-08', '2015-03-09', null, '2');
INSERT INTO `orders` VALUES ('12', '2015-03-08', '2015-03-10', null, '4');
INSERT INTO `orders` VALUES ('13', '2015-03-08', '2015-03-11', null, '5');
INSERT INTO `orders` VALUES ('14', '2015-03-18', '2015-03-20', null, null);
INSERT INTO `orders` VALUES ('15', '2015-04-12', '2015-04-13', '1252.50', '4');

-- ----------------------------
-- Table structure for `ordersdetail`
-- ----------------------------
DROP TABLE IF EXISTS `ordersdetail`;
CREATE TABLE `ordersdetail` (
  `ordersID` int(11) NOT NULL,
  `goodsID` int(11) NOT NULL,
  `quantity` int(11) DEFAULT NULL,
  `money` decimal(10,2) DEFAULT NULL,
  PRIMARY KEY (`ordersID`,`goodsID`),
  KEY `fk3` (`goodsID`),
  CONSTRAINT `fk2` FOREIGN KEY (`ordersID`) REFERENCES `orders` (`ordersID`),
  CONSTRAINT `fk3` FOREIGN KEY (`goodsID`) REFERENCES `goods` (`goodsID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- ----------------------------
-- Records of ordersdetail
-- ----------------------------
INSERT INTO `ordersdetail` VALUES ('1', '2', '2', null);
INSERT INTO `ordersdetail` VALUES ('1', '3', '3', null);
INSERT INTO `ordersdetail` VALUES ('2', '3', '1', null);
INSERT INTO `ordersdetail` VALUES ('2', '4', '2', null);
INSERT INTO `ordersdetail` VALUES ('3', '6', '2', null);
INSERT INTO `ordersdetail` VALUES ('3', '8', '3', null);
INSERT INTO `ordersdetail` VALUES ('4', '5', '2', null);
INSERT INTO `ordersdetail` VALUES ('4', '7', '3', null);
INSERT INTO `ordersdetail` VALUES ('5', '1', '3', null);
INSERT INTO `ordersdetail` VALUES ('5', '3', '2', null);
INSERT INTO `ordersdetail` VALUES ('6', '2', '1', null);
INSERT INTO `ordersdetail` VALUES ('6', '3', '2', null);
INSERT INTO `ordersdetail` VALUES ('6', '4', '3', null);
INSERT INTO `ordersdetail` VALUES ('7', '5', '1', null);
INSERT INTO `ordersdetail` VALUES ('7', '6', '1', null);
INSERT INTO `ordersdetail` VALUES ('8', '3', '3', null);
INSERT INTO `ordersdetail` VALUES ('8', '4', '2', null);
INSERT INTO `ordersdetail` VALUES ('9', '2', '3', null);
INSERT INTO `ordersdetail` VALUES ('10', '4', '2', null);
INSERT INTO `ordersdetail` VALUES ('10', '7', '3', null);
INSERT INTO `ordersdetail` VALUES ('11', '9', '2', null);
INSERT INTO `ordersdetail` VALUES ('11', '10', '3', null);
INSERT INTO `ordersdetail` VALUES ('12', '6', '3', null);
INSERT INTO `ordersdetail` VALUES ('12', '8', '1', null);
INSERT INTO `ordersdetail` VALUES ('13', '8', '3', null);
INSERT INTO `ordersdetail` VALUES ('13', '9', '1', null);
INSERT INTO `ordersdetail` VALUES ('14', '3', '2', null);
INSERT INTO `ordersdetail` VALUES ('14', '8', '2', null);
INSERT INTO `ordersdetail` VALUES ('15', '6', '1', null);
INSERT INTO `ordersdetail` VALUES ('15', '7', '2', null);
INSERT INTO `ordersdetail` VALUES ('15', '10', '3', null);

-- ----------------------------
-- Table structure for `test`
-- ----------------------------
DROP TABLE IF EXISTS `test`;
CREATE TABLE `test` (
  `name` varchar(255) DEFAULT NULL,
  UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of test
-- ----------------------------
INSERT INTO `test` VALUES ('zhang');

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章