文章目录

  • 样例表的下载
    • 创建表
    • 插入数据
  • 具体操作

样例表的下载

这是书中给出的数据下载链接

也可以不用下载,具体的代码如下:

创建表

########################################
# MySQL Crash Course
# http://www.forta.com/books/0672327120/
# Example table creation scripts
################################################################
# Create customers table
########################
CREATE TABLE customers
(cust_id      int       NOT NULL AUTO_INCREMENT,cust_name    char(50)  NOT NULL ,cust_address char(50)  NULL ,cust_city    char(50)  NULL ,cust_state   char(5)   NULL ,cust_zip     char(10)  NULL ,cust_country char(50)  NULL ,cust_contact char(50)  NULL ,cust_email   char(255) NULL ,PRIMARY KEY (cust_id)
) ENGINE=InnoDB;#########################
# Create orderitems table
#########################
CREATE TABLE orderitems
(order_num  int          NOT NULL ,order_item int          NOT NULL ,prod_id    char(10)     NOT NULL ,quantity   int          NOT NULL ,item_price decimal(8,2) NOT NULL ,PRIMARY KEY (order_num, order_item)
) ENGINE=InnoDB;#####################
# Create orders table
#####################
CREATE TABLE orders
(order_num  int      NOT NULL AUTO_INCREMENT,order_date datetime NOT NULL ,cust_id    int      NOT NULL ,PRIMARY KEY (order_num)
) ENGINE=InnoDB;#######################
# Create products table
#######################
CREATE TABLE products
(prod_id    char(10)      NOT NULL,vend_id    int           NOT NULL ,prod_name  char(255)     NOT NULL ,prod_price decimal(8,2)  NOT NULL ,prod_desc  text          NULL ,PRIMARY KEY(prod_id)
) ENGINE=InnoDB;######################
# Create vendors table
######################
CREATE TABLE vendors
(vend_id      int      NOT NULL AUTO_INCREMENT,vend_name    char(50) NOT NULL ,vend_address char(50) NULL ,vend_city    char(50) NULL ,vend_state   char(5)  NULL ,vend_zip     char(10) NULL ,vend_country char(50) NULL ,PRIMARY KEY (vend_id)
) ENGINE=InnoDB;###########################
# Create productnotes table
###########################
CREATE TABLE productnotes
(note_id    int           NOT NULL AUTO_INCREMENT,prod_id    char(10)      NOT NULL,note_date datetime       NOT NULL,note_text  text          NULL ,PRIMARY KEY(note_id),FULLTEXT(note_text)
) ENGINE=MyISAM;#####################
# Define foreign keys
#####################
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);

插入数据

########################################
# MySQL Crash Course
# http://www.forta.com/books/0672327120/
# Example table population scripts
##################################################################
# 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 和其对应的图形化界面 MySQL Workbench 我们已经安装过来,详情见博客,我们在 MySQL Workbench 中进行操作。

1.打开 MySQL Workbench

2.点击 root 用户,输入密码登陆

3.我们创建新的数据库



4.这个就是我们刚刚创建的数据库,要是没有,就点击上面的刷新一下!

5.接下来,我们就可以往这个数据库中新建表了,具体如图所示:


6.我们可以在新建好的表中插入数据

7.刷新一下


8.接下来,就可以愉快的学习了!

《MySQL必知必会》学习笔记——1.书中样例表的生成相关推荐

  1. 微信小程序学习笔记④——Flex布局[实战样例之画骰子]

    ✅ 关于 Flex,很多优秀的前辈已经总结过了,比如:阮一峰的<Flex 布局教程:语法篇>.知乎林东洲的<30 分钟学会 Flex 布局>等等.他们主要是基于网页的,小辈斗胆 ...

  2. 读书笔记系列1——MySQL必知必会

    读书笔记系列1--MySQL必知必会 文章目录 读书笔记系列1--MySQL必知必会 MySQL官方文档:https://dev.mysql.com/doc/ 第一章 数据库基础 *2021.11.2 ...

  3. 《MySQL实战45讲》——学习笔记12 “InnoDB刷脏页的控制策略“

    本篇介绍MYSQL InnoDB的WAL机制带来的小问题--利用WAL技术,数据库将随机写转换成了顺序写,大大提升了数据库的性能,但也带来了内存脏页的问题: 脏页会被后台线程自动flush,也会由于数 ...

  4. 性能调优之JMH必知必会2:JMH的基本用法

    性能调优之JMH必知必会2:JMH的基本用法 JMH必知必会系列文章(持续更新) 一.前言 二.JMH的基本用法 1.添加JMH依赖包 2.@Benchmark 2.@Warmup和@Measurem ...

  5. ASP.Net学习笔记015--ASP.Net中使用Cookie

    ASP.Net学习笔记015--ASP.Net中使用Cookie 表单数据欺骗: 原理跟收到欺骗短信一样,移动信号塔[基站],伪装的移动信号塔会屏蔽移动信号,并且 在信号范围内的手机会自动切换为接收伪 ...

  6. 《MySQL必知必会》学习笔记十(增删改语句使用)------掌握部分

    MySQL必知必会知识预览 第一章--了解SQL 第二章--MySQL简介 第三章--使用MySQL 第四章--检索数据 第五章--排序检索数据 第六章--过滤数据 第七章--数据过滤 第八章--用通 ...

  7. MYSQL必知必会学习笔记(二)

    MYSQL必知必会四-五章--检索.排序 书中部分代码展示: ##第四第五章 SELECT prod_name FROM products; /*从products表中检索一个叫prod_name的列 ...

  8. mysql必知必会学习笔记(一)

    MYSQL必知必会第三章--了解数据库和表 书中部分代码展示: CREATE DATABASE crashcourse; /*创建名为 crashcourse 的新数据库*/SHOW DATABASE ...

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

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

  10. 《MySQL必知必会学习笔记》:更新和删除数据

    更新和删除数据 上篇博文介绍了下插入数据的几种方式.这篇博文就来讲述下更新和删除数据. 更新数据 更新(修改)表中的数据,使用update语句. 更新数据一般采用如下两种方式: 更新表中特定行的数据. ...

最新文章

  1. IEC61850笔记--IEC61850应用入门(二)
  2. 自学python找到工作-学完python能找到工作么
  3. linux 关闭开机 ftp,解决linux ftp匿名上传、下载开机自启问题
  4. 支撑百亿级应用的 NewSQL——TiDB 在同程旅游的应用
  5. 路由器 radius认证获取ip_玩转网络工程师·认证篇
  6. 【最新合集】PAT乙级最优题解(题解+解析+代码)
  7. Error creating bean with name ‘cn.cyjt.shoot.service.UserServiceTests‘: Unsatisfied dependency expre
  8. 微软顶级代码女神,编程界最有权势的女王
  9. 计算机网络研修培训总结,计算机培训工作总结(共10篇).doc
  10. Spring Batch的事务-Part 1:基础
  11. python3 写入excel_python3读取、写入、追加写入excel文件
  12. 数据挖掘中的KNN算法实现论文
  13. 天翼云虚拟IP地址及其在高可用集群中的应用
  14. 电商后台管理系统项目介绍和项目初始化
  15. 1972 年 11 月 29 日:雅达利推出投币式街机游戏《乓》
  16. 超 3000 个特效镜头,复联 4 是如何「速成」的?
  17. IDEA运行web项目路径中去掉项目名称
  18. CTFHub | 弱口令
  19. 手把手教你给 SSH 启用二次身份验证
  20. Android利用jsoup爬虫爬网页数据(一)

热门文章

  1. 科技正在淘汰传统行业,这次的“倒霉鬼”是券商
  2. (转)金丘股份CEO左鹏:用区块链做ABS,实现消费金融ABS创新
  3. 有关SQLite数据库的一些实证数据,有一定历史比较和参考意义
  4. 【时间序列预测】基于matlab最小均方(LMS)算法时间序列预测【含Matlab源码 1335期】
  5. 【优化预测】基于matlab萤火虫算法优化BP神经网络预测【含Matlab源码 1313期】
  6. 【路径规划】基于matlab模拟退火算法求解多车型路径规划问题【含Matlab源码 913期】
  7. 【TSP】基于matlab粒子群算法求解旅行商问题【含Matlab源码 445期】
  8. 建站模板论坛_【714】号称全球最快的无代码拖拽集成建站工具?
  9. r语言 生成等差序列_使用序列模型生成自然语言
  10. glob.glob()、sort() 等一些函数的用法