《MySQL必知必会》SQL文件:

表的创建和外键绑定:

# 在Mysql中取消外键约束
SET FOREIGN_KEY_CHECKS=0;
DROP TABLE customers;
DROP TABLE orderitems;
DROP TABLE orders;
DROP TABLE products;
DROP TABLE vendors;
DROP TABLE productnotes;
# 然后再设置外键约束
SET FOREIGN_KEY_CHECKS=1;  CREATE TABLE customers
(cust_id      int       NOT NULL AUTO_INCREMENT COMMENT '唯一的顾客ID',cust_name    char(50)  NOT NULL COMMENT '顾客名',cust_address char(50)  NULL COMMENT '顾客的地址',cust_city    char(50)  NULL COMMENT '顾客的城市',cust_state   char(5)   NULL COMMENT '顾客的州',cust_zip     char(10)  NULL COMMENT '顾客的邮政编码',cust_country char(50)  NULL COMMENT '顾客的国家',cust_contact char(50)  NULL COMMENT '顾客的联系名',cust_email   char(255) NULL COMMENT '顾客的联系email地址',PRIMARY KEY (cust_id)
) ENGINE=InnoDB;
CREATE TABLE orderitems
(order_num  int          NOT NULL COMMENT '订单号',order_item int          NOT NULL COMMENT '订单物品号',prod_id    char(10)     NOT NULL COMMENT '产品ID',quantity   int          NOT NULL COMMENT '物品数量',item_price decimal(8,2) NOT NULL COMMENT '物品价格',PRIMARY KEY (order_num, order_item)
) ENGINE=InnoDB;
CREATE TABLE orders
(order_num  int      NOT NULL AUTO_INCREMENT COMMENT '唯一订单号',order_date datetime NOT NULL COMMENT '订单日期',cust_id    int      NOT NULL COMMENT '订单顾客ID',PRIMARY KEY (order_num)
) ENGINE=InnoDB;
CREATE TABLE products
(prod_id    char(10)      NOT NULL COMMENT '唯一的产品ID',vend_id    int           NOT NULL COMMENT '产品供应商ID',prod_name  char(255)     NOT NULL COMMENT '产品名',prod_price decimal(8,2)  NOT NULL COMMENT '产品价格',prod_desc  text          NULL COMMENT '产品描述',PRIMARY KEY(prod_id)
) ENGINE=InnoDB;
CREATE TABLE vendors
(vend_id      int      NOT NULL AUTO_INCREMENT COMMENT '唯一的供应商ID',vend_name    char(50) NOT NULL COMMENT '供应商名',vend_address char(50) NULL COMMENT '供应商的地址',vend_city    char(50) NULL COMMENT '供应商的城市',vend_state   char(5)  NULL COMMENT '供应商的州',vend_zip     char(10) NULL COMMENT '供应商的邮政编码',vend_country char(50) NULL COMMENT '供应商的国家',PRIMARY KEY (vend_id)
) ENGINE=InnoDB;
CREATE TABLE productnotes
(note_id    int           NOT NULL AUTO_INCREMENT COMMENT '唯一注释ID',prod_id    char(10)      NOT NULL COMMENT '产品ID',note_date datetime       NOT NULL COMMENT '增加注释的日期',note_text  text          NULL COMMENT '注释文本',PRIMARY KEY(note_id),FULLTEXT(note_text)
) ENGINE=MyISAM;
ALTER TABLE orderitems ADD CONSTRAINT fk_orderitems_orders FOREIGN KEY (order_num) REFERENCES orders (order_num);
ALTER TABLE orderitems ADD CONSTRAINT fk_orderitems_products FOREIGN KEY (prod_id) REFERENCES products (prod_id);
ALTER TABLE orders ADD CONSTRAINT fk_orders_customers FOREIGN KEY (cust_id) REFERENCES customers (cust_id);
ALTER TABLE products ADD CONSTRAINT fk_products_vendors FOREIGN KEY (vend_id) REFERENCES vendors (vend_id);##########################
# Populate customers table
##########################
INSERT INTO customers(cust_id, cust_name, cust_address, cust_city, cust_state, cust_zip, cust_country, cust_contact, cust_email)
VALUES(10001, 'Coyote Inc.', '200 Maple Lane', 'Detroit', 'MI', '44444', 'USA', 'Y Lee', 'ylee@coyote.com');
INSERT INTO customers(cust_id, cust_name, cust_address, cust_city, cust_state, cust_zip, cust_country, cust_contact)
VALUES(10002, 'Mouse House', '333 Fromage Lane', 'Columbus', 'OH', '43333', 'USA', 'Jerry Mouse');
INSERT INTO customers(cust_id, cust_name, cust_address, cust_city, cust_state, cust_zip, cust_country, cust_contact, cust_email)
VALUES(10003, 'Wascals', '1 Sunny Place', 'Muncie', 'IN', '42222', 'USA', 'Jim Jones', 'rabbit@wascally.com');
INSERT INTO customers(cust_id, cust_name, cust_address, cust_city, cust_state, cust_zip, cust_country, cust_contact, cust_email)
VALUES(10004, 'Yosemite Place', '829 Riverside Drive', 'Phoenix', 'AZ', '88888', 'USA', 'Y Sam', 'sam@yosemite.com');
INSERT INTO customers(cust_id, cust_name, cust_address, cust_city, cust_state, cust_zip, cust_country, cust_contact)
VALUES(10005, 'E Fudd', '4545 53rd Street', 'Chicago', 'IL', '54545', 'USA', 'E Fudd');########################
# Populate vendors table
########################
INSERT INTO vendors(vend_id, vend_name, vend_address, vend_city, vend_state, vend_zip, vend_country)
VALUES(1001,'Anvils R Us','123 Main Street','Southfield','MI','48075', 'USA');
INSERT INTO vendors(vend_id, vend_name, vend_address, vend_city, vend_state, vend_zip, vend_country)
VALUES(1002,'LT Supplies','500 Park Street','Anytown','OH','44333', 'USA');
INSERT INTO vendors(vend_id, vend_name, vend_address, vend_city, vend_state, vend_zip, vend_country)
VALUES(1003,'ACME','555 High Street','Los Angeles','CA','90046', 'USA');
INSERT INTO vendors(vend_id, vend_name, vend_address, vend_city, vend_state, vend_zip, vend_country)
VALUES(1004,'Furball Inc.','1000 5th Avenue','New York','NY','11111', 'USA');
INSERT INTO vendors(vend_id, vend_name, vend_address, vend_city, vend_state, vend_zip, vend_country)
VALUES(1005,'Jet Set','42 Galaxy Road','London', NULL,'N16 6PS', 'England');
INSERT INTO vendors(vend_id, vend_name, vend_address, vend_city, vend_state, vend_zip, vend_country)
VALUES(1006,'Jouets Et Ours','1 Rue Amusement','Paris', NULL,'45678', 'France');#########################
# Populate products table
#########################
INSERT INTO products(prod_id, vend_id, prod_name, prod_price, prod_desc)
VALUES('ANV01', 1001, '.5 ton anvil', 5.99, '.5 ton anvil, black, complete with handy hook');
INSERT INTO products(prod_id, vend_id, prod_name, prod_price, prod_desc)
VALUES('ANV02', 1001, '1 ton anvil', 9.99, '1 ton anvil, black, complete with handy hook and carrying case');
INSERT INTO products(prod_id, vend_id, prod_name, prod_price, prod_desc)
VALUES('ANV03', 1001, '2 ton anvil', 14.99, '2 ton anvil, black, complete with handy hook and carrying case');
INSERT INTO products(prod_id, vend_id, prod_name, prod_price, prod_desc)
VALUES('OL1', 1002, 'Oil can', 8.99, 'Oil can, red');
INSERT INTO products(prod_id, vend_id, prod_name, prod_price, prod_desc)
VALUES('FU1', 1002, 'Fuses', 3.42, '1 dozen, extra long');
INSERT INTO products(prod_id, vend_id, prod_name, prod_price, prod_desc)
VALUES('SLING', 1003, 'Sling', 4.49, 'Sling, one size fits all');
INSERT INTO products(prod_id, vend_id, prod_name, prod_price, prod_desc)
VALUES('TNT1', 1003, 'TNT (1 stick)', 2.50, 'TNT, red, single stick');
INSERT INTO products(prod_id, vend_id, prod_name, prod_price, prod_desc)
VALUES('TNT2', 1003, 'TNT (5 sticks)', 10, 'TNT, red, pack of 10 sticks');
INSERT INTO products(prod_id, vend_id, prod_name, prod_price, prod_desc)
VALUES('FB', 1003, 'Bird seed', 10, 'Large bag (suitable for road runners)');
INSERT INTO products(prod_id, vend_id, prod_name, prod_price, prod_desc)
VALUES('FC', 1003, 'Carrots', 2.50, 'Carrots (rabbit hunting season only)');
INSERT INTO products(prod_id, vend_id, prod_name, prod_price, prod_desc)
VALUES('SAFE', 1003, 'Safe', 50, 'Safe with combination lock');
INSERT INTO products(prod_id, vend_id, prod_name, prod_price, prod_desc)
VALUES('DTNTR', 1003, 'Detonator', 13, 'Detonator (plunger powered), fuses not included');
INSERT INTO products(prod_id, vend_id, prod_name, prod_price, prod_desc)
VALUES('JP1000', 1005, 'JetPack 1000', 35, 'JetPack 1000, intended for single use');
INSERT INTO products(prod_id, vend_id, prod_name, prod_price, prod_desc)
VALUES('JP2000', 1005, 'JetPack 2000', 55, 'JetPack 2000, multi-use');#######################
# Populate orders table
#######################
INSERT INTO orders(order_num, order_date, cust_id)
VALUES(20005, '2005-09-01', 10001);
INSERT INTO orders(order_num, order_date, cust_id)
VALUES(20006, '2005-09-12', 10003);
INSERT INTO orders(order_num, order_date, cust_id)
VALUES(20007, '2005-09-30', 10004);
INSERT INTO orders(order_num, order_date, cust_id)
VALUES(20008, '2005-10-03', 10005);
INSERT INTO orders(order_num, order_date, cust_id)
VALUES(20009, '2005-10-08', 10001);###########################
# Populate orderitems table
###########################
INSERT INTO orderitems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20005, 1, 'ANV01', 10, 5.99);
INSERT INTO orderitems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20005, 2, 'ANV02', 3, 9.99);
INSERT INTO orderitems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20005, 3, 'TNT2', 5, 10);
INSERT INTO orderitems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20005, 4, 'FB', 1, 10);
INSERT INTO orderitems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20006, 1, 'JP2000', 1, 55);
INSERT INTO orderitems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20007, 1, 'TNT2', 100, 10);
INSERT INTO orderitems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20008, 1, 'FC', 50, 2.50);
INSERT INTO orderitems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20009, 1, 'FB', 1, 10);
INSERT INTO orderitems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20009, 2, 'OL1', 1, 8.99);
INSERT INTO orderitems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20009, 3, 'SLING', 1, 4.49);
INSERT INTO orderitems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20009, 4, 'ANV03', 1, 14.99);#############################
# Populate productnotes table
#############################
INSERT INTO productnotes(note_id, prod_id, note_date, note_text)
VALUES(101, 'TNT2', '2005-08-17',
'Customer complaint:
Sticks not individually wrapped, too easy to mistakenly detonate all at once.
Recommend individual wrapping.'
);
INSERT INTO productnotes(note_id, prod_id, note_date, note_text)
VALUES(102, 'OL1', '2005-08-18',
'Can shipped full, refills not available.
Need to order new can if refill needed.'
);
INSERT INTO productnotes(note_id, prod_id, note_date, note_text)
VALUES(103, 'SAFE', '2005-08-18',
'Safe is combination locked, combination not provided with safe.
This is rarely a problem as safes are typically blown up or dropped by customers.'
);
INSERT INTO productnotes(note_id, prod_id, note_date, note_text)
VALUES(104, 'FC', '2005-08-19',
'Quantity varies, sold by the sack load.
All guaranteed to be bright and orange, and suitable for use as rabbit bait.'
);
INSERT INTO productnotes(note_id, prod_id, note_date, note_text)
VALUES(105, 'TNT2', '2005-08-20',
'Included fuses are short and have been known to detonate too quickly for some customers.
Longer fuses are available (item FU1) and should be recommended.'
);
INSERT INTO productnotes(note_id, prod_id, note_date, note_text)
VALUES(106, 'TNT2', '2005-08-22',
'Matches not included, recommend purchase of matches or detonator (item DTNTR).'
);
INSERT INTO productnotes(note_id, prod_id, note_date, note_text)
VALUES(107, 'SAFE', '2005-08-23',
'Please note that no returns will be accepted if safe opened using explosives.'
);
INSERT INTO productnotes(note_id, prod_id, note_date, note_text)
VALUES(108, 'ANV01', '2005-08-25',
'Multiple customer returns, anvils failing to drop fast enough or falling backwards on purchaser. Recommend that customer considers using heavier anvils.'
);
INSERT INTO productnotes(note_id, prod_id, note_date, note_text)
VALUES(109, 'ANV03', '2005-09-01',
'Item is extremely heavy. Designed for dropping, not recommended for use with slings, ropes, pulleys, or tightropes.'
);
INSERT INTO productnotes(note_id, prod_id, note_date, note_text)
VALUES(110, 'FC', '2005-09-01',
'Customer complaint: rabbit has been able to detect trap, food apparently less effective now.'
);
INSERT INTO productnotes(note_id, prod_id, note_date, note_text)
VALUES(111, 'SLING', '2005-09-02',
'Shipped unassembled, requires common tools (including oversized hammer).'
);
INSERT INTO productnotes(note_id, prod_id, note_date, note_text)
VALUES(112, 'SAFE', '2005-09-02',
'Customer complaint:
Circular hole in safe floor can apparently be easily cut with handsaw.'
);
INSERT INTO productnotes(note_id, prod_id, note_date, note_text)
VALUES(113, 'ANV01', '2005-09-05',
'Customer complaint:
Not heavy enough to generate flying stars around head of victim. If being purchased for dropping, recommend ANV02 or ANV03 instead.'
);
INSERT INTO productnotes(note_id, prod_id, note_date, note_text)
VALUES(114, 'SAFE', '2005-09-07',
'Call from individual trapped in safe plummeting to the ground, suggests an escape hatch be added.
Comment forwarded to vendor.'
);

《MySQL必知必会》SQL文件相关推荐

  1. mysql日期维表sql文件_《MySQL必知必会》笔记(SQL练习+建表语句)

    站在巨人的肩上 Standing On Shoulders Of Giants 部分转自:https://www.jianshu.com/p/294502893128 https://blog.csd ...

  2. 《MySQL必知必会》所有SQL语句图表集合(可作为查询表使用)---已完结

    本篇文章是对<MySQL必知必会>所有语句知识点的图表集合,适合快速查询遗忘的SQL语句. 本文的脉络结构,首先先给出<MySQL必知必会>的目录和本书中用到的数据表的UML图 ...

  3. 根据SQL必知必会学习SQL(MYSQL)

    很久都没有整理SQL语句了,遇到让写SQL语句的题也很迷茫,所以就重拾一下知识,本文章根据SQL必知必会进行梳理 文章目录 一.检索所有列 1.select 1.1检索单个列 1.2 检索多个列 1. ...

  4. 【SQL】【读书笔记】《MySQL必知必会》

    本文为<MySQL必知必会>[1]读书笔记,用于总结知识点和框架,仅供参考和交流,如有不妥请联系.由于软件版本更新,书中的一些代码已经不再适用,本文主要从SQL基本语句进行增删减.窗口函数 ...

  5. 《SQL必知必会(第5版)》挑战题笔记 | 所用DBMS为Mysql,mysql workbench安装

    文章目录 一.安装 step1:mysql安装 step2:mysql workbench安装 二.下载随书资料 三.代码实战练习 2.2 检索单个列 四.MySQL知识点回顾 五.挑战题 2.9挑战 ...

  6. mysql必_MySQL必知必会(一)

    摘自<MySQL必知必会> 1.1.1 什么是数据库 数据库:保存有组织的数据的容器(通常是一个文件或一组文件) 人们通常用数据库这个术语来代表他们使用的数据库软件.这是不正确的,它是引起 ...

  7. mysql中用完即删用什么_MySQL使用和操作总结(《MySQL必知必会》读书笔记)

    简介 MySQL是一种DBMS,即它是一种数据库软件.DBMS可分为两类:一类是基于共享文件系统的DBMS,另一类是基于客户机--服务器的DBMS.前者用于桌面用途,通常不用于高端或更关键应用. My ...

  8. mysql必知必会_MySQL必知必会

    MySQL必知必会 联结的使用, 子查询, 正则表达式和基于全文本的搜索, 存储过程, 游标, 触发器, 表约束. 了解SQL 数据库基础 电子邮件地址薄里查找名字时, 因特网搜索站点上进行搜索, 验 ...

  9. mysql必知必会_5天学完《MySQL必知必会》学习笔记之第四天

    本篇知识点 更新删除数据.创建操纵表.视图.存储过程 更新和删除数据 使用UPDATE语句更新(修改)表中的数据: 更新表中特定行(使用WHERE语句 更新表中所有行 UPDATE语句以要更新的表名开 ...

最新文章

  1. python array 语法_Python基本语法
  2. 第六篇:基于朴素贝叶斯分类算法的邮件过滤系统
  3. 52次课(mysql用户管理、常用sql语句、 mysql数据库备份恢复)
  4. pc控制iphone的软件_iPhone照片视频传输及HEIC照片转档
  5. php mail执行命令,PHPMailer 命令执行 任意文件读取漏洞利用 【含POC】
  6. 【PyCharm】10个省时间的 PyCharm 技巧
  7. 阿里云keepalived的虚拟ip怎么让外网访问_Keepalived双机热备
  8. java springboot房地产信息管理系统
  9. 太烧脑了,怪不得程序员会掉头发
  10. 新浪实时股票数据接口http://hq.sinajs.cn/list=code
  11. crm管理系统是什么意思 crm系统全称是什么 - whale帷幄
  12. android sd卡名称,Android系统中SD卡各文件夹名称及功能详解
  13. three.js开发全景视频播放器的现实方法
  14. 南阳理工学院计算机学院ACM队成员获奖情况[荣誉记]
  15. stm32采集交流电压信号_基于STM32的交流电压检测.pdf
  16. StarUML开发团队负责人李珉奎交流会-UMLChina讲座-实录
  17. MySQL安装及MySQL8.0新密码认证方式
  18. HTML5印章绘制电子签章图片(中文英文椭圆章、中文英文椭圆印章)
  19. access无法 dolby_Windows10专业版无法安装dolby如何解决
  20. python安装paddlex(虚拟环境快速安装)

热门文章

  1. 年底大标季来袭,一步之遥2.0投标培训班助你实力升级!
  2. 为什么Pod突然就不见了?
  3. 山西师范大学数学与计算机学院宿舍,数计学院宿舍文化节之PPT展示大赛决赛圆满结束...
  4. 大连商务英语培训百家外语国际部怎样提高商务英语阅读技能?
  5. T51:字符流中第一个未重复的字符(Java)
  6. 调起APP功能的实现
  7. python sql语句换行_python一行sql太长折成多行并且有多个参数的方法
  8. html后代选择器和子代选择器,CSS后代选择器与子元素选择器的区别
  9. 超火爆的人类一败涂地Human Fall Flat Mac中文版(支持m1)
  10. 批量PDF文件合并用什么软件?这两个宝藏软件赶快收藏起来