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

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,高可用系列 2核4GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介: 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');
相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。   相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情: https://www.aliyun.com/product/rds/mysql 
相关文章
|
1月前
|
缓存 关系型数据库 BI
使用MYSQL Report分析数据库性能(下)
使用MYSQL Report分析数据库性能
76 3
|
1月前
|
关系型数据库 MySQL 数据库
自建数据库如何迁移至RDS MySQL实例
数据库迁移是一项复杂且耗时的工程,需考虑数据安全、完整性及业务中断影响。使用阿里云数据传输服务DTS,可快速、平滑完成迁移任务,将应用停机时间降至分钟级。您还可通过全量备份自建数据库并恢复至RDS MySQL实例,实现间接迁移上云。
|
28天前
|
关系型数据库 MySQL 分布式数据库
阿里云PolarDB云原生数据库收费价格:MySQL和PostgreSQL详细介绍
阿里云PolarDB兼容MySQL、PostgreSQL及Oracle语法,支持集中式与分布式架构。标准版2核4G年费1116元起,企业版最高性能达4核16G,支持HTAP与多级高可用,广泛应用于金融、政务、互联网等领域,TCO成本降低50%。
|
29天前
|
关系型数据库 MySQL 数据库
阿里云数据库RDS费用价格:MySQL、SQL Server、PostgreSQL和MariaDB引擎收费标准
阿里云RDS数据库支持MySQL、SQL Server、PostgreSQL、MariaDB,多种引擎优惠上线!MySQL倚天版88元/年,SQL Server 2核4G仅299元/年,PostgreSQL 227元/年起。高可用、可弹性伸缩,安全稳定。详情见官网活动页。
|
1月前
|
关系型数据库 分布式数据库 数据库
阿里云数据库收费价格:MySQL、PostgreSQL、SQL Server和MariaDB引擎费用整理
阿里云数据库提供多种类型,包括关系型与NoSQL,主流如PolarDB、RDS MySQL/PostgreSQL、Redis等。价格低至21元/月起,支持按需付费与优惠套餐,适用于各类应用场景。
|
29天前
|
SQL 关系型数据库 MySQL
Mysql数据恢复—Mysql数据库delete删除后数据恢复案例
本地服务器,操作系统为windows server。服务器上部署mysql单实例,innodb引擎,独立表空间。未进行数据库备份,未开启binlog。 人为误操作使用Delete命令删除数据时未添加where子句,导致全表数据被删除。删除后未对该表进行任何操作。需要恢复误删除的数据。 在本案例中的mysql数据库未进行备份,也未开启binlog日志,无法直接还原数据库。
|
1月前
|
Ubuntu 安全 关系型数据库
安装与配置MySQL 8 on Ubuntu,包括权限授予、数据库备份及远程连接指南
以上步骤提供了在Ubuntu上从头开始设置、配置、授权、备份及恢复一个基础但完整的MySQL环境所需知识点。
275 7
|
1月前
|
缓存 监控 关系型数据库
使用MYSQL Report分析数据库性能(上)
最终建议:当前系统是完美的读密集型负载模型,优化重点应放在减少行读取量和提高数据定位效率。通过索引优化、分区策略和内存缓存,预期可降低30%的CPU负载,同时保持100%的缓冲池命中率。建议每百万次查询后刷新统计信息以持续优化
134 6
|
1月前
|
缓存 监控 关系型数据库
使用MYSQL Report分析数据库性能(中)
使用MYSQL Report分析数据库性能
98 1
|
1月前
|
关系型数据库 MySQL 数据库
阿里云数据库RDS支持MySQL、SQL Server、PostgreSQL和MariaDB引擎
阿里云数据库RDS支持MySQL、SQL Server、PostgreSQL和MariaDB引擎,提供高性价比、稳定安全的云数据库服务,适用于多种行业与业务场景。

推荐镜像

更多