Verified Commit 45d3115e authored by Kiryuu Sakuya's avatar Kiryuu Sakuya 🎵
Browse files

Fix database issues & Finish No.3

parent 59fd5e99
......@@ -70,7 +70,7 @@ CREATE TABLE `employee` (
LOCK TABLES `employee` WRITE;
/*!40000 ALTER TABLE `employee` DISABLE KEYS */;
INSERT INTO `employee` VALUES ('10000','马化腾','男','董事会','总经理','2016-10-01 09:00:00','1998-07-11 12:00:00','25111','中华人民共和国北京市西城区西长安街街道','2019-11-10 15:27:57'),('10001','刘强东','男','董事会','副经理','2016-10-01 09:00:00','1974-12-16 15:00:00','20000','深圳市龙华区民治街道梅龙路2号星河盛世','2019-11-10 15:27:57'),('10002','董明珠','女','财务部','会计','2016-10-01 09:00:00','1954-08-01 17:00:00','5251','广州市越秀区培正路2号','2019-11-10 15:27:57'),('10003','张一鸣','男','董事会','财务经理','2016-10-01 09:00:00','1979-02-12 15:30:00','10000','江西省景德镇市珠山区广场北路广瑞公寓一期7号楼1单元201室','2019-11-10 15:27:57'),('10004','张二鸣','男','董事会','人事经理','2016-10-02 14:00:00','1980-03-19 20:01:15','10000','江西省景德镇市珠山区广场北路广瑞公寓一期7号楼1单元201室','2019-11-10 15:27:57'),('10005','张三鸣','女','董事会','办公室主任','2016-10-03 12:42:32','1981-04-20 12:56:22','10000','江西省景德镇市珠山区广场北路广瑞公寓一期7号楼1单元201室','2019-11-10 15:27:57'),('10006','张四鸣','女','董事会','销售经理','2016-10-04 09:15:24','1982-12-10 03:25:59','10000','江西省景德镇市珠山区广场北路广瑞公寓一期7号楼1单元201室','2019-11-10 15:27:57'),('20001','王维林','男','销售部','销售人员','2016-10-01 09:00:00','1989-06-04 23:00:00','3400','北京市东城区台基厂头条14号院','2019-11-10 15:27:57'),('20002','马云','男','销售部','销售人员','2016-10-01 09:00:00','1964-09-10 02:51:00','3600','北京市朝阳区西大望路西大望路甲12号','2019-11-10 15:27:57'),('20003','张五鸣','男','人力资源部','文员','2016-10-05 11:12:13','1985-04-01 02:51:22','3500','江西省景德镇市珠山区广场北路广瑞公寓一期7号楼1单元201室','2019-11-10 15:27:57'),('20004','张六鸣','男','销售部','市场助理','2016-10-05 11:12:13','1986-02-15 09:22:34','4000','江西省景德镇市珠山区广场北路广瑞公寓一期7号楼1单元201室','2019-11-10 15:27:57'),('20005','张七鸣','女','财务部','会计','2016-10-04 21:09:00','1987-02-22 14:28:59','5000','江西省景德镇市珠山区广场北路广瑞公寓一期7号楼1单元201室','2019-11-10 15:27:57'),('20006','张八鸣','女','财务部','出纳','2016-10-09 21:00:00','1988-06-12 14:22:34','4500','江西省景德镇市珠山区广场北路广瑞公寓一期7号楼1单元201室','2019-11-10 15:27:57'),('20007','张九鸣','男','后勤部','主管','2016-10-10 11:23:55','1989-06-04 12:16:00','7500','江西省景德镇市珠山区广场北路广瑞公寓一期7号楼1单元201室','2019-11-10 15:27:57'),('20008','张十鸣','男','后勤部','文员','2017-01-15 15:33:32','1978-12-23 09:22:14','4500','四川省成都市成华区升仙湖北路2号红花堰小区3号楼','2019-11-10 15:27:57'),('99999','龙玉涛','男','NaN','NaN','0000-00-00 00:00:00','0000-00-00 00:00:00','0','NaN','2019-11-10 15:28:31');
INSERT INTO `employee` VALUES ('10000','马化腾','男','董事会','总经理','2016-10-01 09:00:00','1998-07-11 12:00:00','25111','中华人民共和国北京市西城区西长安街街道','2019-11-11 21:45:37'),('10001','刘强东','男','董事会','副经理','2016-10-01 09:00:00','1974-12-16 15:00:00','20000','深圳市龙华区民治街道梅龙路2号星河盛世','2019-11-11 21:45:37'),('10002','董明珠','女','财务部','会计','2016-10-01 09:00:00','1954-08-01 17:00:00','5251','广州市越秀区培正路2号','2019-11-11 21:45:37'),('10003','张一鸣','男','董事会','财务经理','2016-10-01 09:00:00','1979-02-12 15:30:00','10000','江西省景德镇市珠山区广场北路广瑞公寓一期7号楼1单元201室','2019-11-11 21:45:37'),('10004','张二鸣','男','董事会','人事经理','2016-10-02 14:00:00','1980-03-19 20:01:15','10000','江西省景德镇市珠山区广场北路广瑞公寓一期7号楼1单元201室','2019-11-11 21:45:37'),('10005','张三鸣','女','董事会','办公室主任','2016-10-03 12:42:32','1981-04-20 12:56:22','10000','江西省景德镇市珠山区广场北路广瑞公寓一期7号楼1单元201室','2019-11-11 21:45:37'),('10006','张四鸣','女','董事会','销售经理','2016-10-04 09:15:24','1982-12-10 03:25:59','10000','江西省景德镇市珠山区广场北路广瑞公寓一期7号楼1单元201室','2019-11-11 21:45:37'),('20001','王维林','男','销售部','销售人员','2016-10-01 09:00:00','1989-06-04 23:00:00','3400','北京市东城区台基厂头条14号院','2019-11-11 21:45:37'),('20002','马云','男','销售部','销售人员','2016-10-01 09:00:00','1964-09-10 02:51:00','3600','北京市朝阳区西大望路西大望路甲12号','2019-11-11 21:45:37'),('20003','张五鸣','男','人力资源部','文员','2016-10-05 11:12:13','1985-04-01 02:51:22','3500','江西省景德镇市珠山区广场北路广瑞公寓一期7号楼1单元201室','2019-11-11 21:45:37'),('20004','张六鸣','男','销售部','市场助理','2016-10-05 11:12:13','1986-02-15 09:22:34','4000','江西省景德镇市珠山区广场北路广瑞公寓一期7号楼1单元201室','2019-11-11 21:45:37'),('20005','张七鸣','女','财务部','会计','2016-10-04 21:09:00','1987-02-22 14:28:59','5000','江西省景德镇市珠山区广场北路广瑞公寓一期7号楼1单元201室','2019-11-11 21:45:37'),('20006','张八鸣','女','财务部','出纳','2016-10-09 21:00:00','1988-06-12 14:22:34','4500','江西省景德镇市珠山区广场北路广瑞公寓一期7号楼1单元201室','2019-11-11 21:45:37'),('20007','张九鸣','男','后勤部','主管','2016-10-10 11:23:55','1989-06-04 12:16:00','7500','江西省景德镇市珠山区广场北路广瑞公寓一期7号楼1单元201室','2019-11-11 21:45:37'),('20008','张十鸣','男','后勤部','文员','2017-01-15 15:33:32','1978-12-23 09:22:14','4500','四川省成都市成华区升仙湖北路2号红花堰小区3号楼','2019-11-11 21:45:37'),('99999','龙玉涛','男','NaN','NaN','0000-00-00 00:00:00','0000-00-00 00:00:00','0','NaN','2019-11-11 21:45:37');
/*!40000 ALTER TABLE `employee` ENABLE KEYS */;
UNLOCK TABLES;
......@@ -150,7 +150,7 @@ CREATE TABLE `sales` (
LOCK TABLES `sales` WRITE;
/*!40000 ALTER TABLE `sales` DISABLE KEYS */;
INSERT INTO `sales` VALUES ('11035462019090116054034524','100000','20001',56.50,'2019-09-01 16:05:40','2019-09-01 18:23:02','34600350'),('11035462019090211345678134','100001','20002',2510.00,'2019-09-02 11:34:56','2019-09-04 13:01:22','34600352'),('11035462019090312553243345','100002','20001',70.00,'2019-09-03 12:55:32','2019-09-03 15:05:23','34600354'),('11035462019090413452234535','100003','20002',140.00,'2019-09-04 13:45:22','2019-09-04 14:00:00','34600356'),('11035462019090514523456734','100004','20001',10.00,'2019-09-05 14:52:34','2019-09-05 14:52:35','34600358'),('11035462019090609452277643','100005','20001',100.00,'2019-09-06 09:45:22','2019-09-06 17:33:55','34600360'),('11035462019090710231334567','100006','20001',17.20,'2019-09-07 10:23:13','2019-09-07 12:00:05','34600362'),('11035462019090810204462563','100007','20002',5.00,'2019-09-08 10:20:44','2019-09-08 20:45:00','34600364'),('11035462019090923452228404','100008','20002',35.00,'2019-09-09 23:45:22','2019-09-10 00:00:00','34600366'),('11035462019091021342023750','100009','20002',89.00,'2019-09-10 21:34:20','2019-09-11 09:11:32','34600368'),('11035462019091109080728562','100010','20002',50.00,'2019-09-11 09:08:07','2019-09-11 12:06:22','34600370'),('11035462019111100000020957','100012','20002',1.00,'2019-11-11 00:00:00','2019-11-11 08:11:43','34600376'),('11035462019111100000023945','100013','20001',29.00,'2019-11-11 00:00:00','2019-11-11 10:30:22','34600378'),('11035462019111100000036455','100011','20002',350.00,'2019-11-11 00:00:00','2019-11-11 08:11:43','34600374'),('11035462019111100000129425','100008','20001',50.00,'2019-11-11 00:00:01','2019-11-11 10:30:22','34600372');
INSERT INTO `sales` VALUES ('11035462019090116054034524','100000','20001',56.50,'2019-09-01 16:05:40','2019-09-01 18:23:02','34600350'),('11035462019090211345678134','100001','20002',2510.00,'2019-09-02 11:34:56','2019-09-04 13:01:22','34600352'),('11035462019090312553243345','100002','20001',70.00,'2019-09-03 12:55:32','2019-09-03 15:05:23','34600354'),('11035462019090413452234535','100003','20002',140.00,'2019-09-04 13:45:22','2019-09-04 14:00:00','34600356'),('11035462019090514523456734','100004','20001',10.00,'2019-09-05 14:52:34','2019-09-05 14:52:35','34600358'),('11035462019090609452277643','100005','20001',100.00,'2019-09-06 09:45:22','2019-09-06 17:33:55','34600360'),('11035462019090710231334567','100006','20001',17.20,'2019-09-07 10:23:13','2019-09-07 12:00:05','34600362'),('11035462019090810204462563','100007','20002',5.00,'2019-09-08 10:20:44','2019-09-08 20:45:00','34600364'),('11035462019090923452228404','100008','20002',35.00,'2019-09-09 23:45:22','2019-09-10 00:00:00','34600366'),('11035462019091021342023750','100009','20002',89.00,'2019-09-10 21:34:20','2019-09-11 09:11:32','34600368'),('11035462019091109080728562','100010','20002',50.00,'2019-09-11 09:08:07','2019-09-11 12:06:22','34600370'),('11035462019111100000020957','100012','20002',1.00,'2019-11-11 00:00:00','2019-11-11 08:11:43','34600376'),('11035462019111100000029425','100008','20001',50.00,'2019-11-11 00:00:01','2019-11-11 10:30:22','34600372'),('11035462019111100000036455','100011','20002',350.00,'2019-11-11 00:00:00','2019-11-11 08:11:43','34600374'),('11035462019111100000123945','100013','20001',29.00,'2019-11-11 00:00:00','2019-11-11 10:30:22','34600378');
/*!40000 ALTER TABLE `sales` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
......@@ -163,4 +163,4 @@ UNLOCK TABLES;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2019-11-10 15:47:03
-- Dump completed on 2019-11-11 21:46:39
-- MariaDB dump 10.17 Distrib 10.4.10-MariaDB, for Linux (x86_64)
--
-- Host: localhost Database: studentdb
-- ------------------------------------------------------
-- Server version 10.4.10-MariaDB
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table `customer`
--
DROP TABLE IF EXISTS `customer`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `customer` (
`cust_id` char(6) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '客户号',
`cust_name` char(20) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '客户名称',
`addr` char(40) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '客户住址',
`tel_no` char(15) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '客户电话',
`zip` char(8) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '邮政编码',
PRIMARY KEY (`cust_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `customer`
--
LOCK TABLES `customer` WRITE;
/*!40000 ALTER TABLE `customer` DISABLE KEYS */;
INSERT INTO `customer` VALUES ('100000','张三丰','江西省景德镇市浮梁县湘湖镇景德镇陶瓷大学湘湖校区','+86199484935556','333403'),('100001','高濑智章','日本秋田県横手市十文字町西原二番町','+81976313164','127-1196'),('100002','潘易梦','上海市静安区昌平路645弄1-5号东安公寓','+8618834527335','200040'),('100003','袁光文','上海市静安区浙江北路403弄之1-88号华安坊','+8615078342223','200040'),('100004','江渲染','浙江省杭州市下城区河东路136号朝晖五区','+8613044538964','310014'),('100005','黄湘云','浙江省杭州市余杭区瓶窑镇彭公村钱家坞翰泽实业','+8617663452324','311115'),('100006','周玲然','北京市通州区北大街后安福胡同万宁小区15壕楼','+8613802653467','101100'),('100007','郝俨雅','黑龙江省鹤岗市向阳区西红星街红星楼小区3号楼2单元302室','+8619928472345','154100'),('100008','杨德庸','重庆市涪陵区体育北路时代文具','+8618629342495','408000'),('100009','丁建德','青海省海北藏族自治州海晏县三角城镇三角城村','+8617686475333','812299'),('100010','贾宇航','湖南省长沙市开福区希贤里金帆·江滨玫瑰园22栋','+8615133458842','410005'),('100011','龚建章','广东省广州市白云区广州大道北白山村白山东路佳润云凯雅寓2座','+8613057552324','510515'),('100012','于飞宇','海南省海口市龙华区新建街美的','+8617449593235','571156'),('100013','邱锦程','天津市和平区包头道云台花园7号楼','+8615593452093','300020'),('100014','钱嘉赐','西藏自治区拉萨市尼木县续迈乡续迈村中国农业银行','+8615889099999','851317');
/*!40000 ALTER TABLE `customer` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `employee`
--
DROP TABLE IF EXISTS `employee`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `employee` (
`emp_no` char(5) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '员工编号',
`emp_name` char(10) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '员工姓名',
`emp_sex` char(1) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '性别',
`emp_dept` char(5) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '所属部门',
`emp_title` char(6) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '职称',
`emp_date_hired` datetime NOT NULL COMMENT '到职日',
`emp_birthday` datetime NOT NULL COMMENT '生日',
`emp_salary` char(5) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '薪水',
`emp_addr` varchar(60) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '住址',
`emp_mod_date` datetime NOT NULL DEFAULT current_timestamp() COMMENT '操作时间',
PRIMARY KEY (`emp_no`),
CONSTRAINT `Check_Sex` CHECK (`emp_sex` in ('男','女','NaN'))
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `employee`
--
LOCK TABLES `employee` WRITE;
/*!40000 ALTER TABLE `employee` DISABLE KEYS */;
INSERT INTO `employee` VALUES ('10000','马化腾','男','董事会','总经理','2016-10-01 09:00:00','1998-07-11 12:00:00','25111','中华人民共和国北京市西城区西长安街街道','2019-11-11 21:45:37'),('10001','刘强东','男','董事会','副经理','2016-10-01 09:00:00','1974-12-16 15:00:00','20000','深圳市龙华区民治街道梅龙路2号星河盛世','2019-11-11 21:45:37'),('10002','董明珠','女','财务部','会计','2016-10-01 09:00:00','1954-08-01 17:00:00','5251','广州市越秀区培正路2号','2019-11-11 21:45:37'),('10003','张一鸣','男','董事会','财务经理','2016-10-01 09:00:00','1979-02-12 15:30:00','10000','江西省景德镇市珠山区广场北路广瑞公寓一期7号楼1单元201室','2019-11-11 21:45:37'),('10004','张二鸣','男','董事会','人事经理','2016-10-02 14:00:00','1980-03-19 20:01:15','10000','江西省景德镇市珠山区广场北路广瑞公寓一期7号楼1单元201室','2019-11-11 21:45:37'),('10005','张三鸣','女','董事会','办公室主任','2016-10-03 12:42:32','1981-04-20 12:56:22','10000','江西省景德镇市珠山区广场北路广瑞公寓一期7号楼1单元201室','2019-11-11 21:45:37'),('10006','张四鸣','女','董事会','销售经理','2016-10-04 09:15:24','1982-12-10 03:25:59','10000','江西省景德镇市珠山区广场北路广瑞公寓一期7号楼1单元201室','2019-11-11 21:45:37'),('20001','王维林','男','销售部','销售人员','2016-10-01 09:00:00','1989-06-04 23:00:00','3400','北京市东城区台基厂头条14号院','2019-11-11 21:45:37'),('20002','马云','男','销售部','销售人员','2016-10-01 09:00:00','1964-09-10 02:51:00','3600','北京市朝阳区西大望路西大望路甲12号','2019-11-11 21:45:37'),('20003','张五鸣','男','人力资源部','文员','2016-10-05 11:12:13','1985-04-01 02:51:22','3500','江西省景德镇市珠山区广场北路广瑞公寓一期7号楼1单元201室','2019-11-11 21:45:37'),('20004','张六鸣','男','销售部','市场助理','2016-10-05 11:12:13','1986-02-15 09:22:34','4000','江西省景德镇市珠山区广场北路广瑞公寓一期7号楼1单元201室','2019-11-11 21:45:37'),('20005','张七鸣','女','财务部','会计','2016-10-04 21:09:00','1987-02-22 14:28:59','5000','江西省景德镇市珠山区广场北路广瑞公寓一期7号楼1单元201室','2019-11-11 21:45:37'),('20006','张八鸣','女','财务部','出纳','2016-10-09 21:00:00','1988-06-12 14:22:34','4500','江西省景德镇市珠山区广场北路广瑞公寓一期7号楼1单元201室','2019-11-11 21:45:37'),('20007','张九鸣','男','后勤部','主管','2016-10-10 11:23:55','1989-06-04 12:16:00','7500','江西省景德镇市珠山区广场北路广瑞公寓一期7号楼1单元201室','2019-11-11 21:45:37'),('20008','张十鸣','男','后勤部','文员','2017-01-15 15:33:32','1978-12-23 09:22:14','4500','四川省成都市成华区升仙湖北路2号红花堰小区3号楼','2019-11-11 21:45:37'),('99999','龙玉涛','男','NaN','NaN','0000-00-00 00:00:00','0000-00-00 00:00:00','0','NaN','2019-11-11 21:45:37');
/*!40000 ALTER TABLE `employee` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `product`
--
DROP TABLE IF EXISTS `product`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `product` (
`prod_id` char(5) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '产品编号',
`prod_name` char(100) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '产品名称',
PRIMARY KEY (`prod_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `product`
--
LOCK TABLES `product` WRITE;
/*!40000 ALTER TABLE `product` DISABLE KEYS */;
INSERT INTO `product` VALUES ('D0001','このはな綺譚 dアニメストア Prime Video 12 集全 WEB-DL'),('D0002','うらら迷路帖 千箭限量版1/8比例PVC制已涂装完成品手办'),('D0003','日本百乐/PILOT BXS-IC一次性墨胆 新款V5升级版墨胆适用于BXC-V5'),('D0004','日本百乐/PILOT BXC-V5水性笔 V5升级版环保版/可换墨胆/新款水笔'),('D0005','日本PILOT/百乐中性笔BL-P50 P500/针管考试水笔0.5MM水性笔'),('T0001','海飞丝去屑洗发露止痒呵护型 750ml 促销款'),('T0002','舒肤佳柠檬清香健康+清爽系列沐浴露 400ml'),('T0003','红双喜羽毛球拍双拍 成人学生2只装控球全碳素纤维进攻型'),('T0004','山丘熊猫纸 竹浆本色抽纸500 家用整箱卫生纸3层120抽16包再赠3包'),('T0005','家居拖鞋女夏2018新款防滑室内居家用浴室洗澡情侣女士凉拖鞋男士'),('V0001','江西联通10元 联通话费 自动充值 直充快充 快速到账'),('V0002','CSDN代下载 CSDN不限积分 CSDN代下 24h自动发 无需咨询'),('V0003','自动发货 美国苹果5美元 Apple iTunes美金正规卡gift card'),('V0004','niconico 1个月 白金会员账号+PASS(自动发货)'),('V0005','测试商品 请勿拍');
/*!40000 ALTER TABLE `product` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `sale_item`
--
DROP TABLE IF EXISTS `sale_item`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `sale_item` (
`order_no` varchar(26) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '订单编号',
`prod_id` char(5) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '产品编号',
`qty` int(11) NOT NULL COMMENT '销售数量',
`unit_price` decimal(9,2) NOT NULL COMMENT '单价',
`order_date` datetime NOT NULL COMMENT '订单日期',
PRIMARY KEY (`order_no`,`prod_id`),
KEY `prod_id` (`prod_id`),
CONSTRAINT `sale_item_ibfk_1` FOREIGN KEY (`prod_id`) REFERENCES `product` (`prod_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `sale_item`
--
LOCK TABLES `sale_item` WRITE;
/*!40000 ALTER TABLE `sale_item` DISABLE KEYS */;
INSERT INTO `sale_item` VALUES ('11035462019090116054034524','T0001',1,56.50,'2019-09-01 16:05:40'),('11035462019090211345678134','D0002',5,100.40,'2019-09-02 11:34:56'),('11035462019090312553243345','D0003',10,7.00,'2019-09-03 12:55:32'),('11035462019090413452234535','D0003',20,7.00,'2019-09-04 13:45:22'),('11035462019090514523456734','V0001',1,10.00,'2019-09-05 14:52:34'),('11035462019090609452277643','D0005',4,25.00,'2019-09-06 09:45:22'),('11035462019090710231334567','T0005',2,8.60,'2019-09-07 10:23:13'),('11035462019090810204462563','V0004',1,5.00,'2019-09-08 10:20:44'),('11035462019090923452228404','V0003',1,35.00,'2019-09-09 23:45:22'),('11035462019091021342023750','T0003',1,89.00,'2019-09-10 21:34:20'),('11035462019091109080728562','D0004',5,10.00,'2019-09-11 09:08:07'),('11035462019111100000020957','T0004',1,29.00,'2019-11-11 00:00:00'),('11035462019111100000029425','V0003',10,35.00,'2019-11-11 00:00:00'),('11035462019111100000036455','V0002',1,1.00,'2019-11-11 00:00:00'),('11035462019111100000123945','D0004',5,10.00,'2019-11-11 00:00:01');
/*!40000 ALTER TABLE `sale_item` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `sales`
--
DROP TABLE IF EXISTS `sales`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `sales` (
`order_no` varchar(26) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '订单编号',
`cust_id` char(6) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '客户号',
`sale_id` char(5) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '业务员编号',
`tot_amt` decimal(9,2) NOT NULL COMMENT '订单金额',
`order_date` datetime NOT NULL COMMENT '订货日期',
`ship_date` datetime NOT NULL COMMENT '出货日期',
`invoice_no` char(8) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '发票号码',
PRIMARY KEY (`order_no`),
UNIQUE KEY `invoice_no` (`invoice_no`),
KEY `sale_id` (`sale_id`),
KEY `cust_id` (`cust_id`),
CONSTRAINT `sales_ibfk_1` FOREIGN KEY (`sale_id`) REFERENCES `employee` (`emp_no`),
CONSTRAINT `sales_ibfk_2` FOREIGN KEY (`cust_id`) REFERENCES `customer` (`cust_id`),
CONSTRAINT `sales_ibfk_3` FOREIGN KEY (`order_no`) REFERENCES `sale_item` (`order_no`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `sales`
--
LOCK TABLES `sales` WRITE;
/*!40000 ALTER TABLE `sales` DISABLE KEYS */;
INSERT INTO `sales` VALUES ('11035462019090116054034524','100000','20001',56.50,'2019-09-01 16:05:40','2019-09-01 18:23:02','34600350'),('11035462019090211345678134','100001','20002',2510.00,'2019-09-02 11:34:56','2019-09-04 13:01:22','34600352'),('11035462019090312553243345','100002','20001',70.00,'2019-09-03 12:55:32','2019-09-03 15:05:23','34600354'),('11035462019090413452234535','100003','20002',140.00,'2019-09-04 13:45:22','2019-09-04 14:00:00','34600356'),('11035462019090514523456734','100004','20001',10.00,'2019-09-05 14:52:34','2019-09-05 14:52:35','34600358'),('11035462019090609452277643','100005','20001',100.00,'2019-09-06 09:45:22','2019-09-06 17:33:55','34600360'),('11035462019090710231334567','100006','20001',17.20,'2019-09-07 10:23:13','2019-09-07 12:00:05','34600362'),('11035462019090810204462563','100007','20002',5.00,'2019-09-08 10:20:44','2019-09-08 20:45:00','34600364'),('11035462019090923452228404','100008','20002',35.00,'2019-09-09 23:45:22','2019-09-10 00:00:00','34600366'),('11035462019091021342023750','100009','20002',89.00,'2019-09-10 21:34:20','2019-09-11 09:11:32','34600368'),('11035462019091109080728562','100010','20002',50.00,'2019-09-11 09:08:07','2019-09-11 12:06:22','34600370'),('11035462019111100000020957','100012','20002',1.00,'2019-11-11 00:00:00','2019-11-11 08:11:43','34600376'),('11035462019111100000029425','100008','20001',50.00,'2019-11-11 00:00:01','2019-11-11 10:30:22','34600372'),('11035462019111100000036455','100011','20002',350.00,'2019-11-11 00:00:00','2019-11-11 08:11:43','34600374'),('11035462019111100000123945','100013','20001',29.00,'2019-11-11 00:00:00','2019-11-11 10:30:22','34600378');
/*!40000 ALTER TABLE `sales` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2019-11-11 22:23:24
# 实验三
## 名词解释
> Constraint 是约束的意思
约束实际上就是表中数据的限制条件。比如 name 字段中要让其用户名不重复,这就需要添加约束。或者,注册的时候必须要添加邮箱,这也是约束。
### 主键约束
> 即 Primary Key
- 每个表中只能有一个主键。
- 主键值须非空不重复。
- 可设置单字段主键,也可设置多字段联合主键。
- 联合主键中多个字段的数据完全相同时,才违反主键约束。
例如在表级添加主键约束:
```mysql
create table <表名>(
<字段名1> <字段类型1>,
<字段名2> <字段类型2>,
......
<字段名n> <字段类型n>,
[constraint 主键约束名] primary key(字段名1[,字段名2,...字段名n]));
```
已有表添加主键约束:
```mysql
alter table <表名> add [constraint 主键约束名] primary key(字段名);
# 创建无主键约束的表
mysql> create table employee(
-> e_id int,
-> e_name varchar(5),
-> e_sex varchar(5),
-> e_age int,
-> d_id int);
# 添加主键约束
mysql> alter table employee add primary key(e_id);
```
删除主键约束:
```mysql
alter table <表名> drop primary key;
```
### 唯一约束
> 即 Unique
在列表添加唯一约束:
```mysql
create table <表名> (
<字段名1> <字段类型1>,
<字段名2> <字段类型2>,
......
<字段名n> <字段类型n>,
[constraint 唯一约束名] unique (字段名1[,字段名2...字段名n]));
```
### 外键约束
> 即 Foreign Key
#### 外键是什么?
若有两个表 A、B,id 是 A 的主键,而 B 中也有 id 字段,则 id 就是表 B 的外键,外键约束主要用来维护两个表之间数据的一致性。
某个字段添加**外键约束**之后,该字段称为**外键字段**,外键字段中每个数据都是**外键值**
- 外键值可以为 null。
- 外键字段去引用一张表的某个字段的时候,被引用的字段必须具有 unique 约束。
- 有了外键引用之后,表分为父表和子表(在上述假设 A 为班级表,B 为学生表,那么 A 为父表,B 为字表)
- 创建先创建父表,删除先删除子表数据,插入先插入父表数据
外键约束为某一表中某字段的值依赖于另一张表中某字段的值。主键所在的表为主表,外键所在的表为从表;每一个外键值必须与另一个表中的主键值相对应。
```mysql
# 创建一个主表
mysql> create table department(
-> d_id int primary key,
-> d_name varchar(5),
-> d_num int);
# 创建从表的同时添加外键
mysql> create table employee(
-> e_id int primary key,
-> e_name varchar(5),
-> e_sex varchar(5),
-> e_age int,
-> d_id int,
-> foreign key(d_id) references department(d_id));
# 即 [constraint 外键约束名] foreign key(字段名) references <主表>(主键字段)
```
### 检查约束
> 即 Check
用于指定需要检查的限定条件。
```mysql
# 用法是 check(<限定条件>),例如检查年龄大于 0
mysql> create table employee(
-> e_id int primary key,
-> e_name varchar(5),
-> e_sex varchar(5),
-> e_age int,
-> d_id int,
-> check(e_age>=0));
# 在已有添加则为 alter table <表名> add constraint <检查约束名> check(<限定条件>);
```
## 预想的表结构
根据实验二的表情况,我们应进行以下操作:
- `employee`
-`emp_no` 字段设置为主键约束,同时 `sales` 表内的 `sale_id` 字段设置为外键约束
- 添加检查约束,规定 `emp_sex` 字段只能是 `男``女``NaN`
- `customer`
-`cust_id` 字段设置为主键约束,同时 `sales` 表内的 `cust_id` 字段设置为外键约束
- `sales`
- **虽然 `order_no` 是主键约束,但是因为我们在 `sale_item` 这个表内建立了约束,无需再建立**
-`order_date` 字段与 `sale_item` 表内的 `order_date` 字段联系并将后者设置为外键约束
- 这里加是没有意义的行为,而且本身不能用 datetime 来存储时间——应该用 Unix 时间戳来存储
- 添加唯一约束,应用在 `invoice_no` 字段
- `sale_item`
-`order_no` 字段设置为主键约束,同时 `sales` 表内的 `order_no` 字段设置为外键约束
- `product`
-`prod_id` 字段设置为主键约束,同时 `sale_item` 表内的 `prod_id` 字段设置为外键约束
### 示例代码
#### `employee` 表
1. 主键约束已设置
```mysql
# alter table <表名> add [constraint 主键约束名] primary key(字段名);
ALTER TABLE employee ADD PRIMARY KEY (emp_no);
```
2. 外键约束
```mysql
# 没错,是从外键连回主键
ALTER TABLE sales ADD FOREIGN KEY (sale_id) REFERENCES employee(emp_no);
```
3. 检查约束
```mysql
# alter table <表名> add constraint <检查约束名> check(<限定条件>);
ALTER TABLE employee ADD CONSTRAINT Check_Sex CHECK (emp_sex IN ("男", "女", "NaN"));
# 两个的话可以用 AND 或 OR?
```
##### Bonus time!
比如,检查编号是否为五位数
```mysql
ALTER TABLE employee ADD CHECK(emp_no RLIKE "[0-9][0-9][0-9][0-9][0-9]");
```
或者,输入的编号必须以 E 开头的 5 位数编号
```mysql
ALTER TABLE employee ADD CHECK(emp_no RLIKE "[E][0-9][0-9][0-9][0-9][0-9]");
```
其它有趣的
```
mail LIKE "[^0-9]%[@][q][q][.][c][o][m]"
检查邮箱,表示第一个字符不允许是数字,第一个字符与@符号之间是任意字符。后面是固定格式
一些正则表达式:
'_' 为一个字符,比如 A Like "C_"
% 表示任意长度的字符串,比如 B Like "CO_%"
[] 表示括号中所指定范围内的一个字符,比如 C Like "9W0[1-2]"
[^] 表示不在括号中所指定范围内的一个字符,比如 D Like "%[A-D][^1-2]"
```
#### `customer` 表
1. 主键约束已设置
```mysql
ALTER TABLE customer ADD PRIMARY KEY (cust_id);
```
2. 外键约束
```mysql
ALTER TABLE sales ADD FOREIGN KEY (cust_id) REFERENCES customer(cust_id);
```
#### `sales` 表
1. 主键约束已设置
```mysql
ALTER TABLE sales ADD PRIMARY KEY (order_no);
```
2. 外键约束
> 理论上,但行不通。
```mysql
ALTER TABLE sale_item ADD FOREIGN KEY (order_date) REFERENCES sales(order_date);
```
3. 唯一约束
```mysql
# alter table <表名> add [constraint 唯一约束名] unique (字段名);
ALTER TABLE sales ADD UNIQUE(invoice_no);
```
#### `sale_item` 表
外键约束
```mysql
ALTER TABLE sales ADD FOREIGN KEY (order_no) REFERENCES sale_item(order_no);
```
如果输入错误
```mysql
ALTER TABLE sale_item DROP FOREIGN KEY (order_no);
```
#### `product` 表
外键约束
```mysql
ALTER TABLE sale_item ADD FOREIGN KEY (prod_id) REFERENCES product(prod_id);
```
## 其它
找两个表中的不同项
```mysql
SELECT order_no from sale_item where order_date NOT IN (SELECT order_date from sales);
```
\ No newline at end of file
......@@ -136,10 +136,10 @@ INSERT INTO customer (
| 11035462019090923452228404 | 100008 | 20002 | 35 | 2019-09-09 23:45:22 | 2019-09-10 00:00:00 | 34600366 |
| 11035462019091021342023750 | 100009 | 20002 | 89 | 2019-09-10 21:34:20 | 2019-09-11 09:11:32 | 34600368 |
| 11035462019091109080728562 | 100010 | 20002 | 50 | 2019-09-11 09:08:07 | 2019-09-11 12:06:22 | 34600370 |
| 11035462019111100000029425 | 100008 | 20001 | 50 | 2019-11-11 00:00:01 | 2019-11-11 10:30:22 | 34600372 |
| 11035462019111100000036455 | 100011 | 20002 | 350 | 2019-11-11 00:00:00 | 2019-11-11 08:11:43 | 34600374 |
| 11035462019111100000020957 | 100012 | 20002 | 1 | 2019-11-11 00:00:00 | 2019-11-11 08:11:43 | 34600376 |
| 11035462019111100000023945 | 100013 | 20001 | 29 | 2019-11-11 00:00:00 | 2019-11-11 10:30:22 | 34600378 |
| 11035462019111100000129425 | 100008 | 20001 | 50 | 2019-11-11 00:00:01 | 2019-11-11 10:30:22 | 34600372 |
| 11035462019111100000123945 | 100013 | 20001 | 29 | 2019-11-11 00:00:00 | 2019-11-11 10:30:22 | 34600378 |
#### 示例代码
......@@ -168,14 +168,14 @@ INSERT INTO sales (
"11035462019091021342023750", "100009", "20002", "89", "2019-09-10 21:34:20", "2019-09-11 09:11:32", "34600368"
), (
"11035462019091109080728562", "100010", "20002", "50", "2019-09-11 09:08:07", "2019-09-11 12:06:22", "34600370"
), (
"11035462019111100000029425", "100008", "20001", "50", "2019-11-11 00:00:01", "2019-11-11 10:30:22", "34600372"
), (
"11035462019111100000036455", "100011", "20002", "350", "2019-11-11 00:00:00", "2019-11-11 08:11:43", "34600374"
), (
"11035462019111100000020957", "100012", "20002", "1", "2019-11-11 00:00:00", "2019-11-11 08:11:43", "34600376"
), (
"11035462019111100000023945", "100013", "20001", "29", "2019-11-11 00:00:00", "2019-11-11 10:30:22", "34600378"
), (
"11035462019111100000129425", "100008", "20001", "50", "2019-11-11 00:00:01", "2019-11-11 10:30:22", "34600372"
"11035462019111100000123945", "100013", "20001", "29", "2019-11-11 00:00:00", "2019-11-11 10:30:22", "34600378"
);
```
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment