From 3076045f9a13f4e61c9320eb907f6cf891d6c7f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E4=BF=8A=E5=93=B2?= <2361967167@qq.com> Date: Sun, 19 Feb 2023 22:29:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20220219 \344\275\234\344\270\232.md" | 307 ++++++++++++++++++ .../20230218 mysql-base.md" | 26 -- 2 files changed, 307 insertions(+), 26 deletions(-) create mode 100644 "24\351\231\210\344\277\212\345\223\262/20220219 \344\275\234\344\270\232.md" delete mode 100644 "24\351\231\210\344\277\212\345\223\262/20230218 mysql-base.md" diff --git "a/24\351\231\210\344\277\212\345\223\262/20220219 \344\275\234\344\270\232.md" "b/24\351\231\210\344\277\212\345\223\262/20220219 \344\275\234\344\270\232.md" new file mode 100644 index 0000000..4adb2d1 --- /dev/null +++ "b/24\351\231\210\344\277\212\345\223\262/20220219 \344\275\234\344\270\232.md" @@ -0,0 +1,307 @@ +## 第1题 + +1、创建数据库test01_market + +**create database test01_market;** + +2、创建表格customers + +**use test01_market;** + +**create table customers(** + +**c_num int(11),** + +**c_name varchar(50),** + +**c_contact varchar(50),** + +**c_city varchar(50),** + +**c_birth date** + +**);** + +| 字段名 | 数据类型 | +| --------- | ----------- | +| c_num | int(11) | +| c_name | varchar(50) | +| c_contact | varchar(50) | +| c_city | varchar(50) | +| c_birth | date | + +**要求3:**将c_contact字段移动到c_birth字段后面 + +**alter table customers modify c_contact varchar(50) after c_birth;** + +**要求4:**将c_name字段数据类型改为 varchar(70) + + **alter table customers modify c_name varchar(70);** + +**要求5:**将c_contact字段改名为c_phone + +**alter table customers change c_contact c_phone varchar(50);** + +**要求6:**增加c_gender字段到c_name后面,数据类型为char(1) + +**alter table customers add c_gender char(1) after c_name;** + +**要求7:**将表名改为customers_info + +**alter table customers rename to customers_info;** + +**要求8:**删除字段c_city + +**alter table customers_info drop c_city;** + +## 第2题 + +1、创建数据库test02_library + +**create database test02_library;** + +2、创建表格books + +**use test02_library** + +**create table books(** + +**b_id int(11) not null unique comment '书编号',** + +**b_name varchar(50) not null comment '书名',** + +**authors varchar(100) not null comment '作者',** + +**price float not null comment '价格',** + +**pubdate year not null comment '出版日期',** + +**note varchar(100) comment '说明',** + +**num int(11) not null comment '库存'** + +**);** + +| 字段名 | 字段说明 | 数据类型 | 允许为空 | 唯一 | +| ------- | -------- | ------------- | -------- | ---- | +| b_id | 书编号 | int(11) | 否 | 是 | +| b_name | 书名 | varchar(50) | 否 | 否 | +| authors | 作者 | varchar(100) | 否 | 否 | +| price | 价格 | float | 否 | 否 | +| pubdate | 出版日期 | year | 否 | 否 | +| note | 说明 | varchar(100) | 是 | 否 | +| num | 库存 | int(11) | 否 | 否 | + +3、向books表中插入记录 + +1) 指定所有字段名称插入第一条记录 + +**insert into books (b_id,b_name,authors,price,pubdate,note,num) values** + +**(1,'Tal of AAA','Dickes',23,1995,'novel',11);** + +2)不指定字段名称插入第二记录 + +**insert into books values** + +**(2,'EmmaT', 'Jane lura',35,1993,'joke',22);** + +3)同时插入多条记录(剩下的所有记录) + +**insert into books values** + +**(3,'Story of Jane','Jane Tim',40,2001,'novel',0),** + +**(4,'Lovey Day','George Byron',20,2005,'novel',30),** + +**(5,'Old land','Honore Blade',30,2010,'law',0),** + +**(6,'The Battle','Upton Sara',30,1999,'medicine',40),** + +**(7,'Rose Hood','Richard haggard',28,2008,'cartoon',28);** + +| b_id | b_name | authors | price | pubdate | note | num | +| ---- | ------------- | --------------- | ----- | ------- | -------- | ---- | +| 1 | Tal of AAA | Dickes | 23 | 1995 | novel | 11 | +| 2 | EmmaT | Jane lura | 35 | 1993 | joke | 22 | +| 3 | Story of Jane | Jane Tim | 40 | 2001 | novel | 0 | +| 4 | Lovey Day | George Byron | 20 | 2005 | novel | 30 | +| 5 | Old land | Honore Blade | 30 | 2010 | law | 0 | +| 6 | The Battle | Upton Sara | 30 | 1999 | medicine | 40 | +| 7 | Rose Hood | Richard haggard | 28 | 2008 | cartoon | 28 | + +4、将小说类型(novel)的书的价格都增加5。 + +**update books set price=price+5 where note='novel';** + +5、将名称为EmmaT的书的价格改为40。 + +**update books set price=40 where b_name='EmmaT';** + +6、删除库存为0的记录 + +**delete from books where num=0;** + +## 第3题 + +1、创建数据库test03_bookstore + +**create database test03_bookstore;** + +2、创建book表 + +**create database test03_bookstore;** +**USE test03_bookstore;** +**create table book(** +**id int(11) primary key auto_increment,** +**title varchar(100) not null ,** +**author varchar(100) not null,** +**price double(11,2) not null,** +**sales int(11) not null,** +**stock int(11) not null,** +**img_path varchar(100) not null** +**);** + +```mysql ++----------+--------------+------+-----+---------+----------------+ +| Field | Type | Null | Key | Default | Extra | ++----------+--------------+------+-----+---------+----------------+ +| id | int(11) | NO | PRI | NULL | auto_increment | +| title | varchar(100) | NO | | NULL | | +| author | varchar(100) | NO | | NULL | | +| price | double(11,2) | NO | | NULL | | +| sales | int(11) | NO | | NULL | | +| stock | int(11) | NO | | NULL | | +| img_path | varchar(100) | NO | | NULL | | ++----------+--------------+------+-----+---------+----------------+ +``` + +尝试添加部分模拟数据,参考示例如下: + +**insert book values (1,'解忧杂货店','东野圭吾',27.20,102,98,'upload/books/解忧杂货店.jpg'),** + +**(2,'边城','沈从文',23.00,102,98,'upload/books/边城.jpg');** + +```mysql ++----+-------------+------------+-------+-------+-------+----------------------------+ +| id | title | author | price | sales | stock | img_path | ++----+-------------+------------+-------+-------+-------+-----------------------------+ +| 1 | 解忧杂货店 | 东野圭吾 | 27.20 | 102 | 98 | upload/books/解忧杂货店.jpg | +| 2 | 边城 | 沈从文 | 23.00 | 102 | 98 | upload/books/边城.jpg | ++----+---------------+------------+-------+-------+-------+----------------------------+ +``` + +3、创建用户表users,并插入数据 + +**create users(** +**id int(11) primary key auto_increment,** +**username varchar(100) not null unique ,** +**password varchar(100) not null ,** +**email varchar(100)** +**);** + +```mysql ++----------+--------------+------+-----+---------+----------------+ +| Field | Type | Null | Key | Default | Extra | ++----------+--------------+------+-----+---------+----------------+ +| id | int(11) | NO | PRI | NULL | auto_increment | +| username | varchar(100) | NO | UNI | NULL | | +| password | varchar(100) | NO | | NULL | | +| email | varchar(100) | YES | | NULL | | ++----------+--------------+------+-----+---------+----------------+ +``` + +尝试添加部分模拟数据,参考示例如下: + +**insert users values (1,'admin','112233','admin@mxdx.com' );** + +```mysql ++----+----------+----------------------------------+--------------------+ +| id | username | password | email | ++----+----------+----------------------------------+--------------------+ +| 1 | admin | 112233 | admin@mxdx.com | ++----+----------+----------------------------------+--------------------+ +``` + +4、创建订单表orders + +**create table orders(** +**id varchar(100) primary key ,** +**order_time datetime not null ,** +**total_count int(11) not null ,** +**total_amount double(11,2) not null ,** +**state int(11) not null ,** +**user_id int(11) not null** +**);** +**alter table orders add index (user_id);** + +```mysql ++--------------+--------------+------+-----+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++--------------+--------------+------+-----+---------+-------+ +| id | varchar(100) | NO | PRI | NULL | | +| order_time | datetime | NO | | NULL | | +| total_count | int(11) | NO | | NULL | | +| total_amount | double(11,2) | NO | | NULL | | +| state | int(11) | NO | | NULL | | +| user_id | int(11) | NO | MUL | NULL | | ++--------------+--------------+------+-----+---------+-------+ +``` + +尝试添加部分模拟数据,参考示例如下: + +**insert into orders values ('15294258455691 ','2018-06-20 00:30:45',2,50.20,0,1);** + +```mysql ++----------------+---------------------+-------------+--------------+-------+---------+ +| id | order_time | total_count | total_amount | state | user_id | ++----------------+---------------------+-------------+--------------+-------+---------+ +| 15294258455691 | 2018-06-20 00:30:45 | 2 | 50.20 | 0 | 1 | ++----------------+---------------------+-------------+--------------+-------+---------+ +``` + +5、创建订单明细表order_items + +**create table order_items(** +**id int(11) primary key auto_increment,** +**count int(11) not null ,** +**amount double(11,2) not null ,** +**title varchar(100) not null ,** +**author varchar(100)not null ,** +**price double(11,2) not null ,** +**img_path varchar(100)not null ,** +**order_id varchar(100) not null** +**);** +**alter table order_items add index (order_id);** + +```mysql ++----------+--------------+------+-----+---------+----------------+ +| Field | Type | Null | Key | Default | Extra | ++----------+--------------+------+-----+---------+----------------+ +| id | int(11) | NO | PRI | NULL | auto_increment | +| count | int(11) | NO | | NULL | | +| amount | double(11,2) | NO | | NULL | | +| title | varchar(100) | NO | | NULL | | +| author | varchar(100) | NO | | NULL | | +| price | double(11,2) | NO | | NULL | | +| img_path | varchar(100) | NO | | NULL | | +| order_id | varchar(100) | NO | MUL | NULL | | ++----------+--------------+------+-----+---------+----------------+ +``` + +尝试添加部分模拟数据,参考示例如下: + +**insert into order_items values** +**(1,1,27.20,'解忧杂货店','东野圭吾',27.20,'static/img/default.jpg','15294258455691'),** +**(2,1,23.00,'边城','沈从文',23.00,'static/img/default.jpg','15294258455691');** + +```mysql ++----+-------+--------+---------+---------+-------+----------------+----------------+ +| id |count| amount| title | author | price | img_path | order_id | ++----+-------+--------+------------+----------+-------+----------------+----------------+ +| 1 | 1 | 27.20| 解忧杂货店 | 东野圭吾 | 27.20 | static/img/default.jpg|15294258455691 | +| 2 | 1 | 23.00| 边城 | 沈从文 | 23.00 | static/img/default.jpg|15294258455691 | ++----+-------+--------+------------+----------+-------+------------+----------------+ +``` + + diff --git "a/24\351\231\210\344\277\212\345\223\262/20230218 mysql-base.md" "b/24\351\231\210\344\277\212\345\223\262/20230218 mysql-base.md" deleted file mode 100644 index 8d5703b..0000000 --- "a/24\351\231\210\344\277\212\345\223\262/20230218 mysql-base.md" +++ /dev/null @@ -1,26 +0,0 @@ - - -作业: - -数据库class3 -表student -字段:学号,姓名,性别,爱好,住址,联系方式,邮箱,QQ号 -并新增一条自己的记录。 - -~~~mysql -create database class3; -use class3; -create table student( - id char(2) comment '学号', - name varchar(4) comment '姓名', - gender char(1) comment '性别', - aihao varchar(20) comment '爱好', - address varchar(20) comment '地址', - ph_number char(11) comment '联系方式', - email char(17) comment '邮箱', - qq char(10) comment 'QQ号' -); -insert into student values ('24','陈俊哲','男','发呆','福建','10086','123@qq.com','236199676'); -select * from student; -~~~ - -- Gitee