MySQL创建数据库 easyShopping,包括area表、goods表、customer表、orders表、ordersdetall表、test表

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群版 2核4GB 100GB
推荐场景:
搭建个人博客
云数据库 RDS MySQL,高可用版 2核4GB 50GB
简介: MySQL创建数据库 easyShopping,包括area表、goods表、customer表、orders表、ordersdetall表、test表

MySQL创建数据库 easyShopping,包括area表、goods表、customer表、orders表、ordersdetall表、test表


商品表表结构:


76.png


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
);


顾客表表结构:


77.png


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
);


订单表表结构:


78.png


完整语法:


/*
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');
相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
1天前
|
SQL 运维 关系型数据库
|
1天前
|
存储 关系型数据库 MySQL
|
1天前
|
存储 关系型数据库 MySQL
|
1天前
|
关系型数据库 MySQL 数据库
数据迁移脚本优化过程:从 MySQL 到 Django 模型表
在大规模的数据迁移过程中,性能问题往往是开发者面临的主要挑战之一。本文将分析一个数据迁移脚本的优化过程,展示如何从 MySQL 数据库迁移数据到 Django 模型表,并探讨优化前后的性能差异。
|
1天前
|
消息中间件 关系型数据库 Serverless
函数计算产品使用问题之如何通过vpc来连接rds数据库
函数计算产品作为一种事件驱动的全托管计算服务,让用户能够专注于业务逻辑的编写,而无需关心底层服务器的管理与运维。你可以有效地利用函数计算产品来支撑各类应用场景,从简单的数据处理到复杂的业务逻辑,实现快速、高效、低成本的云上部署与运维。以下是一些关于使用函数计算产品的合集和要点,帮助你更好地理解和应用这一服务。
|
2天前
|
关系型数据库 MySQL 数据库
MySQL mysqldump教程:轻松备份与迁移数据库
MySQL mysqldump教程:轻松备份与迁移数据库
|
1天前
|
关系型数据库 MySQL 分布式数据库
PolarDB产品使用问题之要验证MySQL迁移后的数据库数据与迁移前的数据一致性,该怎么办
PolarDB产品使用合集涵盖了从创建与管理、数据管理、性能优化与诊断、安全与合规到生态与集成、运维与支持等全方位的功能和服务,旨在帮助企业轻松构建高可用、高性能且易于管理的数据库环境,满足不同业务场景的需求。用户可以通过阿里云控制台、API、SDK等方式便捷地使用这些功能,实现数据库的高效运维与持续优化。
PolarDB产品使用问题之要验证MySQL迁移后的数据库数据与迁移前的数据一致性,该怎么办
|
19小时前
|
关系型数据库 MySQL 数据库
深入OceanBase分布式数据库:MySQL 模式下的 SQL 基本操作
深入OceanBase分布式数据库:MySQL 模式下的 SQL 基本操作
5 0
|
23小时前
|
存储 缓存 关系型数据库
心得经验总结:理解MySQL——并行数据库与分区(Partion)
心得经验总结:理解MySQL——并行数据库与分区(Partion)
|
2天前
|
存储 SQL 关系型数据库
【MYSQL】数据库基础
【MYSQL】数据库基础
10 0

热门文章

最新文章