From 001e4e418b38bb191123ba471b54e126ffb0f848 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=9C=87=E6=B4=8B?= <11785166+hzyai77@user.noreply.gitee.com> Date: Wed, 22 Feb 2023 04:54:09 +0000 Subject: [PATCH 01/12] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20=E9=9F=A9=E9=9C=87?= =?UTF-8?q?=E6=B4=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "\351\237\251\351\234\207\346\264\213/.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "\351\237\251\351\234\207\346\264\213/.keep" diff --git "a/\351\237\251\351\234\207\346\264\213/.keep" "b/\351\237\251\351\234\207\346\264\213/.keep" new file mode 100644 index 0000000..e69de29 -- Gitee From db6200cbe50b1a4bccafbc3fb35c404a5e6a11a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=9C=87=E6=B4=8B?= <11785166+hzyai77@user.noreply.gitee.com> Date: Wed, 22 Feb 2023 04:56:46 +0000 Subject: [PATCH 02/12] =?UTF-8?q?=E9=9F=A9=E9=9C=87=E6=B4=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 韩震洋 <11785166+hzyai77@user.noreply.gitee.com> --- .../\351\237\251\351\234\207\346\264\213.txt" | 489 ++++++++++++++++++ 1 file changed, 489 insertions(+) create mode 100644 "\351\237\251\351\234\207\346\264\213/\351\237\251\351\234\207\346\264\213.txt" diff --git "a/\351\237\251\351\234\207\346\264\213/\351\237\251\351\234\207\346\264\213.txt" "b/\351\237\251\351\234\207\346\264\213/\351\237\251\351\234\207\346\264\213.txt" new file mode 100644 index 0000000..b981c2f --- /dev/null +++ "b/\351\237\251\351\234\207\346\264\213/\351\237\251\351\234\207\346\264\213.txt" @@ -0,0 +1,489 @@ +mysql> show databases; ++--------------------+ +| Database | ++--------------------+ +| information_schema | +| mysql | +| performance_schema | +| sys | +| test | +| test01_market | +| test02_library | ++--------------------+ +7 rows in set (0.00 sec) + +mysql> select * from books; +ERROR 1046 (3D000): No database selected +mysql> use test02__library; +ERROR 1049 (42000): Unknown database 'test02__library' +mysql> use test02_library; +Database changed +mysql> select * from books; ++------+--------+---------+-------+---------+--------+-----+ +| b_id | b_name | authors | price | pubdate | note | num | ++------+--------+---------+-------+---------+--------+-----+ +| 1 | qiqi | qi | 7 | 2020 | kunkun | 101 | ++------+--------+---------+-------+---------+--------+-----+ +1 row in set (0.00 sec) + +mysql> delete from books where b_id=5; +Query OK, 0 rows affected (0.00 sec) + +mysql> select * from books; ++------+--------+---------+-------+---------+--------+-----+ +| b_id | b_name | authors | price | pubdate | note | num | ++------+--------+---------+-------+---------+--------+-----+ +| 1 | qiqi | qi | 7 | 2020 | kunkun | 101 | ++------+--------+---------+-------+---------+--------+-----+ +1 row in set (0.00 sec) + +mysql> delete from books ; +Query OK, 1 row affected (0.01 sec) + +mysql> select * from books; +Empty set (0.00 sec) + +mysql> desc books; ++---------+--------------+------+-----+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++---------+--------------+------+-----+---------+-------+ +| b_id | int(11) | NO | PRI | NULL | | +| b_name | varchar(50) | NO | | NULL | | +| authors | varchar(100) | NO | | NULL | | +| price | float | NO | | NULL | | +| pubdate | year(4) | NO | | NULL | | +| note | varchar(100) | YES | | NULL | | +| num | int(11) | NO | | NULL | | ++---------+--------------+------+-----+---------+-------+ +7 rows in set (0.00 sec) + +mysql> insert into books values (1,'tal of aaa','dickes',23,1995,'novel',11); +Query OK, 1 row affected (0.01 sec) + +mysql> select * from books; ++------+------------+---------+-------+---------+-------+-----+ +| b_id | b_name | authors | price | pubdate | note | num | ++------+------------+---------+-------+---------+-------+-----+ +| 1 | tal of aaa | dickes | 23 | 1995 | novel | 11 | ++------+------------+---------+-------+---------+-------+-----+ +1 row in set (0.00 sec) + +mysql> insert into books values (2,'emmat','jane lura',35,1993,'joke',22); +Query OK, 1 row affected (0.01 sec) + +mysql> select * from books; ++------+------------+-----------+-------+---------+-------+-----+ +| 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 | ++------+------------+-----------+-------+---------+-------+-----+ +2 rows in set (0.00 sec) + +mysql> insert into books values(3,'story of jane','jane tim',40,2001,'novel',0); +Query OK, 1 row affected (0.01 sec) + +mysql> select * from books; ++------+---------------+-----------+-------+---------+-------+-----+ +| 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 | ++------+---------------+-----------+-------+---------+-------+-----+ +3 rows in set (0.00 sec) + +mysql> insert into books values (4,'lovey day','george byron',20,2005,'novel',30); +Query OK, 1 row affected (0.01 sec) + +mysql> select * from books; ++------+---------------+--------------+-------+---------+-------+-----+ +| 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 | ++------+---------------+--------------+-------+---------+-------+-----+ +4 rows in set (0.00 sec) + +mysql> insert into books values(5,'old land','honore blade',30,2010,'law',0); +Query OK, 1 row affected (0.01 sec) + +mysql> select * from books; ++------+---------------+--------------+-------+---------+-------+-----+ +| 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 | ++------+---------------+--------------+-------+---------+-------+-----+ +5 rows in set (0.00 sec) + +mysql> insert into books values(6,'the battle','upton sara',30,1999,'medicine',40); +Query OK, 1 row affected (0.01 sec) + +mysql> select * from books; ++------+---------------+--------------+-------+---------+----------+-----+ +| 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 | ++------+---------------+--------------+-------+---------+----------+-----+ +6 rows in set (0.00 sec) + +mysql> insert into books values(7,'rose hood','richard haggard',28,2008,'cartoon',28); +Query OK, 1 row affected (0.00 sec) + +mysql> select * from books; ++------+---------------+-----------------+-------+---------+----------+-----+ +| 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 | ++------+---------------+-----------------+-------+---------+----------+-----+ +7 rows in set (0.00 sec) + +mysql> update books set price = 28 where b_name = tal of aaa; +ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'of aaa' at line 1 +mysql> update books set price = 28 where b_name = 'tal of aaa'; +Query OK, 1 row affected (0.01 sec) +Rows matched: 1 Changed: 1 Warnings: 0 + +mysql> select * from books; ++------+---------------+-----------------+-------+---------+----------+-----+ +| b_id | b_name | authors | price | pubdate | note | num | ++------+---------------+-----------------+-------+---------+----------+-----+ +| 1 | tal of aaa | dickes | 28 | 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 | ++------+---------------+-----------------+-------+---------+----------+-----+ +7 rows in set (0.00 sec) + +mysql> update books set price = 40 where b_name = 'emmat'; +Query OK, 1 row affected (0.01 sec) +Rows matched: 1 Changed: 1 Warnings: 0 + +mysql> select * from books; ++------+---------------+-----------------+-------+---------+----------+-----+ +| b_id | b_name | authors | price | pubdate | note | num | ++------+---------------+-----------------+-------+---------+----------+-----+ +| 1 | tal of aaa | dickes | 28 | 1995 | novel | 11 | +| 2 | emmat | jane lura | 40 | 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 | ++------+---------------+-----------------+-------+---------+----------+-----+ +7 rows in set (0.00 sec) + +mysql> update books set price = 45 where b_name = 'story of jane'; +Query OK, 1 row affected (0.01 sec) +Rows matched: 1 Changed: 1 Warnings: 0 + +mysql> select * from books; ++------+---------------+-----------------+-------+---------+----------+-----+ +| b_id | b_name | authors | price | pubdate | note | num | ++------+---------------+-----------------+-------+---------+----------+-----+ +| 1 | tal of aaa | dickes | 28 | 1995 | novel | 11 | +| 2 | emmat | jane lura | 40 | 1993 | joke | 22 | +| 3 | story of jane | jane tim | 45 | 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 | ++------+---------------+-----------------+-------+---------+----------+-----+ +7 rows in set (0.00 sec) + +mysql> update books set price = 25 where b_name = 'jane tim'; +Query OK, 0 rows affected (0.00 sec) +Rows matched: 0 Changed: 0 Warnings: 0 + +mysql> update books set price = 45 where b_name = 'jane tim'; +Query OK, 0 rows affected (0.00 sec) +Rows matched: 0 Changed: 0 Warnings: 0 + +mysql> select * from books; ++------+---------------+-----------------+-------+---------+----------+-----+ +| b_id | b_name | authors | price | pubdate | note | num | ++------+---------------+-----------------+-------+---------+----------+-----+ +| 1 | tal of aaa | dickes | 28 | 1995 | novel | 11 | +| 2 | emmat | jane lura | 40 | 1993 | joke | 22 | +| 3 | story of jane | jane tim | 45 | 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 | ++------+---------------+-----------------+-------+---------+----------+-----+ +7 rows in set (0.00 sec) + +mysql> update books set price = 25 where name = 'georege byron'; +ERROR 1054 (42S22): Unknown column 'name' in 'where clause' +mysql> update books set price = 25 where b_name = 'georege byron'; +Query OK, 0 rows affected (0.00 sec) +Rows matched: 0 Changed: 0 Warnings: 0 + +mysql> update books set price = 35 where b_name = 'honore blade'; +Query OK, 0 rows affected (0.00 sec) +Rows matched: 0 Changed: 0 Warnings: 0 + +mysql> update books set prcie = 35 where b_name = 'upton sara'; +ERROR 1054 (42S22): Unknown column 'prcie' in 'field list' +mysql> update books set price = 35 where b_name = 'upton sara'; +Query OK, 0 rows affected (0.00 sec) +Rows matched: 0 Changed: 0 Warnings: 0 + +mysql> update books set price = 33 where b_name = 'richard haggard'; +Query OK, 0 rows affected (0.00 sec) +Rows matched: 0 Changed: 0 Warnings: 0 + +mysql> select * from books; ++------+---------------+-----------------+-------+---------+----------+-----+ +| b_id | b_name | authors | price | pubdate | note | num | ++------+---------------+-----------------+-------+---------+----------+-----+ +| 1 | tal of aaa | dickes | 28 | 1995 | novel | 11 | +| 2 | emmat | jane lura | 40 | 1993 | joke | 22 | +| 3 | story of jane | jane tim | 45 | 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 | ++------+---------------+-----------------+-------+---------+----------+-----+ +7 rows in set (0.00 sec) + +mysql> update books set price = 25 where b_name = 'lovey day'; +Query OK, 1 row affected (0.01 sec) +Rows matched: 1 Changed: 1 Warnings: 0 + +mysql> select * from books; ++------+---------------+-----------------+-------+---------+----------+-----+ +| b_id | b_name | authors | price | pubdate | note | num | ++------+---------------+-----------------+-------+---------+----------+-----+ +| 1 | tal of aaa | dickes | 28 | 1995 | novel | 11 | +| 2 | emmat | jane lura | 40 | 1993 | joke | 22 | +| 3 | story of jane | jane tim | 45 | 2001 | novel | 0 | +| 4 | lovey day | george byron | 25 | 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 | ++------+---------------+-----------------+-------+---------+----------+-----+ +7 rows in set (0.00 sec) + +mysql> update books set price = 35 where name = 'old land' or name = 'the battle'; +ERROR 1054 (42S22): Unknown column 'name' in 'where clause' +mysql> +mysql> update books set price = 35 where b_name = 'old land' or b_name = 'the battle'; +Query OK, 2 rows affected (0.01 sec) +Rows matched: 2 Changed: 2 Warnings: 0 + +mysql> select * from books; ++------+---------------+-----------------+-------+---------+----------+-----+ +| b_id | b_name | authors | price | pubdate | note | num | ++------+---------------+-----------------+-------+---------+----------+-----+ +| 1 | tal of aaa | dickes | 28 | 1995 | novel | 11 | +| 2 | emmat | jane lura | 40 | 1993 | joke | 22 | +| 3 | story of jane | jane tim | 45 | 2001 | novel | 0 | +| 4 | lovey day | george byron | 25 | 2005 | novel | 30 | +| 5 | old land | honore blade | 35 | 2010 | law | 0 | +| 6 | the battle | upton sara | 35 | 1999 | medicine | 40 | +| 7 | rose hood | richard haggard | 28 | 2008 | cartoon | 28 | ++------+---------------+-----------------+-------+---------+----------+-----+ +7 rows in set (0.00 sec) + +mysql> update books set price = 33 where b_name = 'rose hood'; +Query OK, 1 row affected (0.01 sec) +Rows matched: 1 Changed: 1 Warnings: 0 + +mysql> select * from books; ++------+---------------+-----------------+-------+---------+----------+-----+ +| b_id | b_name | authors | price | pubdate | note | num | ++------+---------------+-----------------+-------+---------+----------+-----+ +| 1 | tal of aaa | dickes | 28 | 1995 | novel | 11 | +| 2 | emmat | jane lura | 40 | 1993 | joke | 22 | +| 3 | story of jane | jane tim | 45 | 2001 | novel | 0 | +| 4 | lovey day | george byron | 25 | 2005 | novel | 30 | +| 5 | old land | honore blade | 35 | 2010 | law | 0 | +| 6 | the battle | upton sara | 35 | 1999 | medicine | 40 | +| 7 | rose hood | richard haggard | 33 | 2008 | cartoon | 28 | ++------+---------------+-----------------+-------+---------+----------+-----+ +7 rows in set (0.00 sec) + +mysql> delete from books where num = 0; +Query OK, 2 rows affected (0.01 sec) + +mysql> select * from books; ++------+------------+-----------------+-------+---------+----------+-----+ +| b_id | b_name | authors | price | pubdate | note | num | ++------+------------+-----------------+-------+---------+----------+-----+ +| 1 | tal of aaa | dickes | 28 | 1995 | novel | 11 | +| 2 | emmat | jane lura | 40 | 1993 | joke | 22 | +| 4 | lovey day | george byron | 25 | 2005 | novel | 30 | +| 6 | the battle | upton sara | 35 | 1999 | medicine | 40 | +| 7 | rose hood | richard haggard | 33 | 2008 | cartoon | 28 | ++------+------------+-----------------+-------+---------+----------+-----+ +5 rows in set (0.00 sec) + +mysql> create database test03_bookstore varchar utf8; +ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'varchar utf8' at line 1 +mysql> create database test03_bookstore charset utf8; +Query OK, 1 row affected (0.00 sec) + +mysql> show databases; ++--------------------+ +| Database | ++--------------------+ +| information_schema | +| mysql | +| performance_schema | +| sys | +| test | +| test01_market | +| test02_library | +| test03_bookstore | ++--------------------+ +8 rows in set (0.00 sec) + +mysql> use test03_bookstore; +Database changed +mysql> create table book( + -> id int(11) not null primary key); +Query OK, 0 rows affected (0.02 sec) + +mysql> desc talbe; +ERROR 1146 (42S02): Table 'test03_bookstore.talbe' doesn't exist +mysql> desc book; ++-------+---------+------+-----+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++-------+---------+------+-----+---------+-------+ +| id | int(11) | NO | PRI | NULL | | ++-------+---------+------+-----+---------+-------+ +1 row in set (0.00 sec) + +mysql> drop book; +ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'book' at line 1 +mysql> drop table book; +Query OK, 0 rows affected (0.01 sec) + +mysql> create table book( + -> id int(11) not null primary key, + -> ; +ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 2 +mysql> create table book( + -> id int(11) not null primary key auto_increment, + -> title varchar(100) not null, + -> author varchar(100), + -> price double(11,2) not null, + -> sales int(11) not null, + -> stock int(11) not null, + -> img_path varchar(100) not null); +Query OK, 0 rows affected (0.01 sec) + +mysql> desc book; ++----------+--------------+------+-----+---------+----------------+ +| Field | Type | Null | Key | Default | Extra | ++----------+--------------+------+-----+---------+----------------+ +| id | int(11) | NO | PRI | NULL | auto_increment | +| title | varchar(100) | NO | | NULL | | +| author | varchar(100) | YES | | NULL | | +| price | double(11,2) | NO | | NULL | | +| sales | int(11) | NO | | NULL | | +| stock | int(11) | NO | | NULL | | +| img_path | varchar(100) | NO | | NULL | | ++----------+--------------+------+-----+---------+----------------+ +7 rows in set (0.00 sec) + +mysql> alter table author not null; +ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'not null' at line 1 +mysql> alter table author add not null; +ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'not null' at line 1 +mysql> alter table author modify varchar(100) not null; +ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'varchar(100) not null' at line 1 +mysql> alter table book modify author varchar(100) ont null; +ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ont null' at line 1 +mysql> alter table book modify author varchar(100) not null; +Query OK, 0 rows affected (0.02 sec) +Records: 0 Duplicates: 0 Warnings: 0 + +mysql> desc table book;; +ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'table book' at line 1 +ERROR: +No query specified + +mysql> desc book; ++----------+--------------+------+-----+---------+----------------+ +| 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 | | ++----------+--------------+------+-----+---------+----------------+ +7 rows in set (0.00 sec) + +mysql> insert into book values(1,'解忧杂货店','东野奎吾',27.20,102,98,'upload/books/解忧杂货店.jpg'); +Query OK, 1 row affected (0.00 sec) + +mysql> select * from book; ++----+------------+----------+-------+-------+-------+-----------------------------+ +| id | title | author | price | sales | stock | img_path | ++----+------------+----------+-------+-------+-------+-----------------------------+ +| 1 | 解忧杂货店 | 东野奎吾 | 27.20 | 102 | 98 | upload/books/解忧杂货店.jpg | ++----+------------+----------+-------+-------+-------+-----------------------------+ +1 row in set (0.00 sec) + +mysql> insert into book values(2,,‘边城','沈从文',23.00,102,98,'upload/books/边城.jpg'); + '> ; + '> insert into book values(2,,‘边城','沈从文',23.00,102,98,'upload/books/边城.jpg'); +ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '‘边城','沈从文',23.00,102,98,'upload/books/边城.jpg'); +; +insert into bo' at line 1 +mysql> insert into book values(2,‘边城','沈从文',23.00,102,98,'upload/books/边城.jpg'); + '> ; + '> insert into book values(2,‘边城','沈从文',23.00,102,98,'upload/books/边城.jpg'); +ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '','沈从文',23.00,102,98,'upload/books/边城.jpg'); +; +insert into book values' at line 1 +mysql> insert into book values (2,‘边城','沈从文',23.00,102,98,'upload/books/边城.jpg'); + '> insert into book values (2,'边城','沈从文',23.00,102,98,'upload/books/边城.jpg'); + '> insert into book values (2,'边城','沈从文',23.00,102,98,'upload/books/边城.jpg'); + '> insert into book values (2,'边城','沈从文',23.00,102,98,'upload/books/边城.jpg'); + '> ; + '> ' + -> ;; +ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '','沈从文',23.00,102,98,'upload/books/边城.jpg'); +insert into book values (' at line 1 +ERROR: +No query specified + +mysql> insert into book values(2,'边城','沈从文',23.00,102,98,'upload/books/边城.jpg'); +Query OK, 1 row affected (0.01 sec) + +mysql> select * from book; ++----+------------+----------+-------+-------+-------+-----------------------------+ +| id | title | author | price | sales | stock | img_path | ++----+------------+----------+-------+-------+-------+-----------------------------+ +| 1 | 解忧杂货店 | 东野奎吾 | 27.20 | 102 | 98 | upload/books/解忧杂货店.jpg | +| 2 | 边城 | 沈从文 | 23.00 | 102 | 98 | upload/books/边城.jpg | ++----+------------+----------+-------+-------+-------+-----------------------------+ +2 rows in set (0.00 sec) + +mysql> \ No newline at end of file -- Gitee From 6263f1749979e90728f81cf9760aa6488ad964ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=9C=87=E6=B4=8B?= <11785166+hzyai77@user.noreply.gitee.com> Date: Wed, 22 Feb 2023 14:08:56 +0000 Subject: [PATCH 03/12] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20?= =?UTF-8?q?=E9=9F=A9=E9=9C=87=E6=B4=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "\351\237\251\351\234\207\346\264\213/.keep" | 0 .../\351\237\251\351\234\207\346\264\213.txt" | 489 ------------------ 2 files changed, 489 deletions(-) delete mode 100644 "\351\237\251\351\234\207\346\264\213/.keep" delete mode 100644 "\351\237\251\351\234\207\346\264\213/\351\237\251\351\234\207\346\264\213.txt" diff --git "a/\351\237\251\351\234\207\346\264\213/.keep" "b/\351\237\251\351\234\207\346\264\213/.keep" deleted file mode 100644 index e69de29..0000000 diff --git "a/\351\237\251\351\234\207\346\264\213/\351\237\251\351\234\207\346\264\213.txt" "b/\351\237\251\351\234\207\346\264\213/\351\237\251\351\234\207\346\264\213.txt" deleted file mode 100644 index b981c2f..0000000 --- "a/\351\237\251\351\234\207\346\264\213/\351\237\251\351\234\207\346\264\213.txt" +++ /dev/null @@ -1,489 +0,0 @@ -mysql> show databases; -+--------------------+ -| Database | -+--------------------+ -| information_schema | -| mysql | -| performance_schema | -| sys | -| test | -| test01_market | -| test02_library | -+--------------------+ -7 rows in set (0.00 sec) - -mysql> select * from books; -ERROR 1046 (3D000): No database selected -mysql> use test02__library; -ERROR 1049 (42000): Unknown database 'test02__library' -mysql> use test02_library; -Database changed -mysql> select * from books; -+------+--------+---------+-------+---------+--------+-----+ -| b_id | b_name | authors | price | pubdate | note | num | -+------+--------+---------+-------+---------+--------+-----+ -| 1 | qiqi | qi | 7 | 2020 | kunkun | 101 | -+------+--------+---------+-------+---------+--------+-----+ -1 row in set (0.00 sec) - -mysql> delete from books where b_id=5; -Query OK, 0 rows affected (0.00 sec) - -mysql> select * from books; -+------+--------+---------+-------+---------+--------+-----+ -| b_id | b_name | authors | price | pubdate | note | num | -+------+--------+---------+-------+---------+--------+-----+ -| 1 | qiqi | qi | 7 | 2020 | kunkun | 101 | -+------+--------+---------+-------+---------+--------+-----+ -1 row in set (0.00 sec) - -mysql> delete from books ; -Query OK, 1 row affected (0.01 sec) - -mysql> select * from books; -Empty set (0.00 sec) - -mysql> desc books; -+---------+--------------+------+-----+---------+-------+ -| Field | Type | Null | Key | Default | Extra | -+---------+--------------+------+-----+---------+-------+ -| b_id | int(11) | NO | PRI | NULL | | -| b_name | varchar(50) | NO | | NULL | | -| authors | varchar(100) | NO | | NULL | | -| price | float | NO | | NULL | | -| pubdate | year(4) | NO | | NULL | | -| note | varchar(100) | YES | | NULL | | -| num | int(11) | NO | | NULL | | -+---------+--------------+------+-----+---------+-------+ -7 rows in set (0.00 sec) - -mysql> insert into books values (1,'tal of aaa','dickes',23,1995,'novel',11); -Query OK, 1 row affected (0.01 sec) - -mysql> select * from books; -+------+------------+---------+-------+---------+-------+-----+ -| b_id | b_name | authors | price | pubdate | note | num | -+------+------------+---------+-------+---------+-------+-----+ -| 1 | tal of aaa | dickes | 23 | 1995 | novel | 11 | -+------+------------+---------+-------+---------+-------+-----+ -1 row in set (0.00 sec) - -mysql> insert into books values (2,'emmat','jane lura',35,1993,'joke',22); -Query OK, 1 row affected (0.01 sec) - -mysql> select * from books; -+------+------------+-----------+-------+---------+-------+-----+ -| 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 | -+------+------------+-----------+-------+---------+-------+-----+ -2 rows in set (0.00 sec) - -mysql> insert into books values(3,'story of jane','jane tim',40,2001,'novel',0); -Query OK, 1 row affected (0.01 sec) - -mysql> select * from books; -+------+---------------+-----------+-------+---------+-------+-----+ -| 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 | -+------+---------------+-----------+-------+---------+-------+-----+ -3 rows in set (0.00 sec) - -mysql> insert into books values (4,'lovey day','george byron',20,2005,'novel',30); -Query OK, 1 row affected (0.01 sec) - -mysql> select * from books; -+------+---------------+--------------+-------+---------+-------+-----+ -| 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 | -+------+---------------+--------------+-------+---------+-------+-----+ -4 rows in set (0.00 sec) - -mysql> insert into books values(5,'old land','honore blade',30,2010,'law',0); -Query OK, 1 row affected (0.01 sec) - -mysql> select * from books; -+------+---------------+--------------+-------+---------+-------+-----+ -| 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 | -+------+---------------+--------------+-------+---------+-------+-----+ -5 rows in set (0.00 sec) - -mysql> insert into books values(6,'the battle','upton sara',30,1999,'medicine',40); -Query OK, 1 row affected (0.01 sec) - -mysql> select * from books; -+------+---------------+--------------+-------+---------+----------+-----+ -| 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 | -+------+---------------+--------------+-------+---------+----------+-----+ -6 rows in set (0.00 sec) - -mysql> insert into books values(7,'rose hood','richard haggard',28,2008,'cartoon',28); -Query OK, 1 row affected (0.00 sec) - -mysql> select * from books; -+------+---------------+-----------------+-------+---------+----------+-----+ -| 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 | -+------+---------------+-----------------+-------+---------+----------+-----+ -7 rows in set (0.00 sec) - -mysql> update books set price = 28 where b_name = tal of aaa; -ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'of aaa' at line 1 -mysql> update books set price = 28 where b_name = 'tal of aaa'; -Query OK, 1 row affected (0.01 sec) -Rows matched: 1 Changed: 1 Warnings: 0 - -mysql> select * from books; -+------+---------------+-----------------+-------+---------+----------+-----+ -| b_id | b_name | authors | price | pubdate | note | num | -+------+---------------+-----------------+-------+---------+----------+-----+ -| 1 | tal of aaa | dickes | 28 | 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 | -+------+---------------+-----------------+-------+---------+----------+-----+ -7 rows in set (0.00 sec) - -mysql> update books set price = 40 where b_name = 'emmat'; -Query OK, 1 row affected (0.01 sec) -Rows matched: 1 Changed: 1 Warnings: 0 - -mysql> select * from books; -+------+---------------+-----------------+-------+---------+----------+-----+ -| b_id | b_name | authors | price | pubdate | note | num | -+------+---------------+-----------------+-------+---------+----------+-----+ -| 1 | tal of aaa | dickes | 28 | 1995 | novel | 11 | -| 2 | emmat | jane lura | 40 | 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 | -+------+---------------+-----------------+-------+---------+----------+-----+ -7 rows in set (0.00 sec) - -mysql> update books set price = 45 where b_name = 'story of jane'; -Query OK, 1 row affected (0.01 sec) -Rows matched: 1 Changed: 1 Warnings: 0 - -mysql> select * from books; -+------+---------------+-----------------+-------+---------+----------+-----+ -| b_id | b_name | authors | price | pubdate | note | num | -+------+---------------+-----------------+-------+---------+----------+-----+ -| 1 | tal of aaa | dickes | 28 | 1995 | novel | 11 | -| 2 | emmat | jane lura | 40 | 1993 | joke | 22 | -| 3 | story of jane | jane tim | 45 | 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 | -+------+---------------+-----------------+-------+---------+----------+-----+ -7 rows in set (0.00 sec) - -mysql> update books set price = 25 where b_name = 'jane tim'; -Query OK, 0 rows affected (0.00 sec) -Rows matched: 0 Changed: 0 Warnings: 0 - -mysql> update books set price = 45 where b_name = 'jane tim'; -Query OK, 0 rows affected (0.00 sec) -Rows matched: 0 Changed: 0 Warnings: 0 - -mysql> select * from books; -+------+---------------+-----------------+-------+---------+----------+-----+ -| b_id | b_name | authors | price | pubdate | note | num | -+------+---------------+-----------------+-------+---------+----------+-----+ -| 1 | tal of aaa | dickes | 28 | 1995 | novel | 11 | -| 2 | emmat | jane lura | 40 | 1993 | joke | 22 | -| 3 | story of jane | jane tim | 45 | 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 | -+------+---------------+-----------------+-------+---------+----------+-----+ -7 rows in set (0.00 sec) - -mysql> update books set price = 25 where name = 'georege byron'; -ERROR 1054 (42S22): Unknown column 'name' in 'where clause' -mysql> update books set price = 25 where b_name = 'georege byron'; -Query OK, 0 rows affected (0.00 sec) -Rows matched: 0 Changed: 0 Warnings: 0 - -mysql> update books set price = 35 where b_name = 'honore blade'; -Query OK, 0 rows affected (0.00 sec) -Rows matched: 0 Changed: 0 Warnings: 0 - -mysql> update books set prcie = 35 where b_name = 'upton sara'; -ERROR 1054 (42S22): Unknown column 'prcie' in 'field list' -mysql> update books set price = 35 where b_name = 'upton sara'; -Query OK, 0 rows affected (0.00 sec) -Rows matched: 0 Changed: 0 Warnings: 0 - -mysql> update books set price = 33 where b_name = 'richard haggard'; -Query OK, 0 rows affected (0.00 sec) -Rows matched: 0 Changed: 0 Warnings: 0 - -mysql> select * from books; -+------+---------------+-----------------+-------+---------+----------+-----+ -| b_id | b_name | authors | price | pubdate | note | num | -+------+---------------+-----------------+-------+---------+----------+-----+ -| 1 | tal of aaa | dickes | 28 | 1995 | novel | 11 | -| 2 | emmat | jane lura | 40 | 1993 | joke | 22 | -| 3 | story of jane | jane tim | 45 | 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 | -+------+---------------+-----------------+-------+---------+----------+-----+ -7 rows in set (0.00 sec) - -mysql> update books set price = 25 where b_name = 'lovey day'; -Query OK, 1 row affected (0.01 sec) -Rows matched: 1 Changed: 1 Warnings: 0 - -mysql> select * from books; -+------+---------------+-----------------+-------+---------+----------+-----+ -| b_id | b_name | authors | price | pubdate | note | num | -+------+---------------+-----------------+-------+---------+----------+-----+ -| 1 | tal of aaa | dickes | 28 | 1995 | novel | 11 | -| 2 | emmat | jane lura | 40 | 1993 | joke | 22 | -| 3 | story of jane | jane tim | 45 | 2001 | novel | 0 | -| 4 | lovey day | george byron | 25 | 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 | -+------+---------------+-----------------+-------+---------+----------+-----+ -7 rows in set (0.00 sec) - -mysql> update books set price = 35 where name = 'old land' or name = 'the battle'; -ERROR 1054 (42S22): Unknown column 'name' in 'where clause' -mysql> -mysql> update books set price = 35 where b_name = 'old land' or b_name = 'the battle'; -Query OK, 2 rows affected (0.01 sec) -Rows matched: 2 Changed: 2 Warnings: 0 - -mysql> select * from books; -+------+---------------+-----------------+-------+---------+----------+-----+ -| b_id | b_name | authors | price | pubdate | note | num | -+------+---------------+-----------------+-------+---------+----------+-----+ -| 1 | tal of aaa | dickes | 28 | 1995 | novel | 11 | -| 2 | emmat | jane lura | 40 | 1993 | joke | 22 | -| 3 | story of jane | jane tim | 45 | 2001 | novel | 0 | -| 4 | lovey day | george byron | 25 | 2005 | novel | 30 | -| 5 | old land | honore blade | 35 | 2010 | law | 0 | -| 6 | the battle | upton sara | 35 | 1999 | medicine | 40 | -| 7 | rose hood | richard haggard | 28 | 2008 | cartoon | 28 | -+------+---------------+-----------------+-------+---------+----------+-----+ -7 rows in set (0.00 sec) - -mysql> update books set price = 33 where b_name = 'rose hood'; -Query OK, 1 row affected (0.01 sec) -Rows matched: 1 Changed: 1 Warnings: 0 - -mysql> select * from books; -+------+---------------+-----------------+-------+---------+----------+-----+ -| b_id | b_name | authors | price | pubdate | note | num | -+------+---------------+-----------------+-------+---------+----------+-----+ -| 1 | tal of aaa | dickes | 28 | 1995 | novel | 11 | -| 2 | emmat | jane lura | 40 | 1993 | joke | 22 | -| 3 | story of jane | jane tim | 45 | 2001 | novel | 0 | -| 4 | lovey day | george byron | 25 | 2005 | novel | 30 | -| 5 | old land | honore blade | 35 | 2010 | law | 0 | -| 6 | the battle | upton sara | 35 | 1999 | medicine | 40 | -| 7 | rose hood | richard haggard | 33 | 2008 | cartoon | 28 | -+------+---------------+-----------------+-------+---------+----------+-----+ -7 rows in set (0.00 sec) - -mysql> delete from books where num = 0; -Query OK, 2 rows affected (0.01 sec) - -mysql> select * from books; -+------+------------+-----------------+-------+---------+----------+-----+ -| b_id | b_name | authors | price | pubdate | note | num | -+------+------------+-----------------+-------+---------+----------+-----+ -| 1 | tal of aaa | dickes | 28 | 1995 | novel | 11 | -| 2 | emmat | jane lura | 40 | 1993 | joke | 22 | -| 4 | lovey day | george byron | 25 | 2005 | novel | 30 | -| 6 | the battle | upton sara | 35 | 1999 | medicine | 40 | -| 7 | rose hood | richard haggard | 33 | 2008 | cartoon | 28 | -+------+------------+-----------------+-------+---------+----------+-----+ -5 rows in set (0.00 sec) - -mysql> create database test03_bookstore varchar utf8; -ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'varchar utf8' at line 1 -mysql> create database test03_bookstore charset utf8; -Query OK, 1 row affected (0.00 sec) - -mysql> show databases; -+--------------------+ -| Database | -+--------------------+ -| information_schema | -| mysql | -| performance_schema | -| sys | -| test | -| test01_market | -| test02_library | -| test03_bookstore | -+--------------------+ -8 rows in set (0.00 sec) - -mysql> use test03_bookstore; -Database changed -mysql> create table book( - -> id int(11) not null primary key); -Query OK, 0 rows affected (0.02 sec) - -mysql> desc talbe; -ERROR 1146 (42S02): Table 'test03_bookstore.talbe' doesn't exist -mysql> desc book; -+-------+---------+------+-----+---------+-------+ -| Field | Type | Null | Key | Default | Extra | -+-------+---------+------+-----+---------+-------+ -| id | int(11) | NO | PRI | NULL | | -+-------+---------+------+-----+---------+-------+ -1 row in set (0.00 sec) - -mysql> drop book; -ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'book' at line 1 -mysql> drop table book; -Query OK, 0 rows affected (0.01 sec) - -mysql> create table book( - -> id int(11) not null primary key, - -> ; -ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 2 -mysql> create table book( - -> id int(11) not null primary key auto_increment, - -> title varchar(100) not null, - -> author varchar(100), - -> price double(11,2) not null, - -> sales int(11) not null, - -> stock int(11) not null, - -> img_path varchar(100) not null); -Query OK, 0 rows affected (0.01 sec) - -mysql> desc book; -+----------+--------------+------+-----+---------+----------------+ -| Field | Type | Null | Key | Default | Extra | -+----------+--------------+------+-----+---------+----------------+ -| id | int(11) | NO | PRI | NULL | auto_increment | -| title | varchar(100) | NO | | NULL | | -| author | varchar(100) | YES | | NULL | | -| price | double(11,2) | NO | | NULL | | -| sales | int(11) | NO | | NULL | | -| stock | int(11) | NO | | NULL | | -| img_path | varchar(100) | NO | | NULL | | -+----------+--------------+------+-----+---------+----------------+ -7 rows in set (0.00 sec) - -mysql> alter table author not null; -ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'not null' at line 1 -mysql> alter table author add not null; -ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'not null' at line 1 -mysql> alter table author modify varchar(100) not null; -ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'varchar(100) not null' at line 1 -mysql> alter table book modify author varchar(100) ont null; -ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ont null' at line 1 -mysql> alter table book modify author varchar(100) not null; -Query OK, 0 rows affected (0.02 sec) -Records: 0 Duplicates: 0 Warnings: 0 - -mysql> desc table book;; -ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'table book' at line 1 -ERROR: -No query specified - -mysql> desc book; -+----------+--------------+------+-----+---------+----------------+ -| 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 | | -+----------+--------------+------+-----+---------+----------------+ -7 rows in set (0.00 sec) - -mysql> insert into book values(1,'解忧杂货店','东野奎吾',27.20,102,98,'upload/books/解忧杂货店.jpg'); -Query OK, 1 row affected (0.00 sec) - -mysql> select * from book; -+----+------------+----------+-------+-------+-------+-----------------------------+ -| id | title | author | price | sales | stock | img_path | -+----+------------+----------+-------+-------+-------+-----------------------------+ -| 1 | 解忧杂货店 | 东野奎吾 | 27.20 | 102 | 98 | upload/books/解忧杂货店.jpg | -+----+------------+----------+-------+-------+-------+-----------------------------+ -1 row in set (0.00 sec) - -mysql> insert into book values(2,,‘边城','沈从文',23.00,102,98,'upload/books/边城.jpg'); - '> ; - '> insert into book values(2,,‘边城','沈从文',23.00,102,98,'upload/books/边城.jpg'); -ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '‘边城','沈从文',23.00,102,98,'upload/books/边城.jpg'); -; -insert into bo' at line 1 -mysql> insert into book values(2,‘边城','沈从文',23.00,102,98,'upload/books/边城.jpg'); - '> ; - '> insert into book values(2,‘边城','沈从文',23.00,102,98,'upload/books/边城.jpg'); -ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '','沈从文',23.00,102,98,'upload/books/边城.jpg'); -; -insert into book values' at line 1 -mysql> insert into book values (2,‘边城','沈从文',23.00,102,98,'upload/books/边城.jpg'); - '> insert into book values (2,'边城','沈从文',23.00,102,98,'upload/books/边城.jpg'); - '> insert into book values (2,'边城','沈从文',23.00,102,98,'upload/books/边城.jpg'); - '> insert into book values (2,'边城','沈从文',23.00,102,98,'upload/books/边城.jpg'); - '> ; - '> ' - -> ;; -ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '','沈从文',23.00,102,98,'upload/books/边城.jpg'); -insert into book values (' at line 1 -ERROR: -No query specified - -mysql> insert into book values(2,'边城','沈从文',23.00,102,98,'upload/books/边城.jpg'); -Query OK, 1 row affected (0.01 sec) - -mysql> select * from book; -+----+------------+----------+-------+-------+-------+-----------------------------+ -| id | title | author | price | sales | stock | img_path | -+----+------------+----------+-------+-------+-------+-----------------------------+ -| 1 | 解忧杂货店 | 东野奎吾 | 27.20 | 102 | 98 | upload/books/解忧杂货店.jpg | -| 2 | 边城 | 沈从文 | 23.00 | 102 | 98 | upload/books/边城.jpg | -+----+------------+----------+-------+-------+-------+-----------------------------+ -2 rows in set (0.00 sec) - -mysql> \ No newline at end of file -- Gitee From 1da2f4e80f5e939f6250671feb408913a06fe35e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=9C=87=E6=B4=8B?= <11785166+hzyai77@user.noreply.gitee.com> Date: Wed, 22 Feb 2023 14:10:25 +0000 Subject: [PATCH 04/12] =?UTF-8?q?=E6=96=B0=E5=BB=BA=2040=20=E9=9F=A9?= =?UTF-8?q?=E9=9C=87=E6=B4=8B=2020230220=E7=BA=A6=E6=9D=9F=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A=E5=92=8C=E7=AC=94=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "40 \351\237\251\351\234\207\346\264\213 20230220\347\272\246\346\235\237\344\275\234\344\270\232\345\222\214\347\254\224\350\256\260/.keep" diff --git "a/40 \351\237\251\351\234\207\346\264\213 20230220\347\272\246\346\235\237\344\275\234\344\270\232\345\222\214\347\254\224\350\256\260/.keep" "b/40 \351\237\251\351\234\207\346\264\213 20230220\347\272\246\346\235\237\344\275\234\344\270\232\345\222\214\347\254\224\350\256\260/.keep" new file mode 100644 index 0000000..e69de29 -- Gitee From 49adcc49b677bdf199f191326fdf49480cf7f3ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=9C=87=E6=B4=8B?= <11785166+hzyai77@user.noreply.gitee.com> Date: Wed, 22 Feb 2023 14:11:22 +0000 Subject: [PATCH 05/12] =?UTF-8?q?40=20=E9=9F=A9=E9=9C=87=E6=B4=8B=20202302?= =?UTF-8?q?20=E7=BA=A6=E6=9D=9F=E4=BD=9C=E4=B8=9A=2040=20=E9=9F=A9?= =?UTF-8?q?=E9=9C=87=E6=B4=8B=2020230220=E7=BA=A6=E6=9D=9F=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 韩震洋 <11785166+hzyai77@user.noreply.gitee.com> --- ...40\344\270\216\344\275\234\344\270\232.md" | 305 ++++++++++++++++++ 1 file changed, 305 insertions(+) create mode 100644 "40 \351\237\251\351\234\207\346\264\213-20230220 \347\272\246\346\235\237\347\232\204\345\255\246\344\271\240\344\270\216\344\275\234\344\270\232.md" diff --git "a/40 \351\237\251\351\234\207\346\264\213-20230220 \347\272\246\346\235\237\347\232\204\345\255\246\344\271\240\344\270\216\344\275\234\344\270\232.md" "b/40 \351\237\251\351\234\207\346\264\213-20230220 \347\272\246\346\235\237\347\232\204\345\255\246\344\271\240\344\270\216\344\275\234\344\270\232.md" new file mode 100644 index 0000000..726e517 --- /dev/null +++ "b/40 \351\237\251\351\234\207\346\264\213-20230220 \347\272\246\346\235\237\347\232\204\345\255\246\344\271\240\344\270\216\344\275\234\344\270\232.md" @@ -0,0 +1,305 @@ +笔记 +学习 +主键,外键,默认值,自增,唯一约束,非空 + +主键:primary key (非空 唯一) + +cr ta 表格名( + 字段 类型 primary key + 或者 primary key(字段1,字段2) + 或primary key(字段) +); +#建表后增加主键: +alter table 表名 add primary key(字段 (可以多个)) +#删除: +alter table 表名 drop primary key; +外键:foreign key + +cr ta 表格名( + 字段 类型, + foreign key (字段) references 主表(字段); (no update/delete x)外键等级 + +); +默认值:default + +cr ta 表格名( + 字段 类型 default 默认值 +); +#默认值:一般不和唯一约束和主键一起加; + +#建表后增加默认值: +alter table 表名 modify default 默认值 (not null); 看有没有加 +#删除 +alter table 表名 modify 字段名 数据类型 (not null); 看有没有加 +自增:auto_increment + +唯一约束:unique key + +非空:not null + +cr ta 表格名( + 字段 类型 not null +); +2.作业 +第一题 + +-- 1、创建数据库test01_company +create database test01_company charset utf8; +-- 2、创建表格offices +use test01_company; +create table offices( + officeCode int, + city varchar(30), + address varchar(50), + country varchar(50), + postalCode varchar(25) + +); +-- +-- | 字段名 | 数据类型 | +-- | ---------- | ----------- | +-- | officeCode | int | +-- | city | varchar(30) | +-- | address | varchar(50) | +-- | country | varchar(50) | +-- | postalCode | varchar(25) | +-- +-- 3、创建表格employees + create table employees( + empNum int, + lastName varchar(50), + firstName varchar(50), + mobile varchar(50), + code int, + jobTitle varchar(50), + birth date, + Note varchar(255), + Sex varchar(5) + ); + +-- | 字段名 | 数据类型 | +-- | --------- | ------------- | +-- | empNum | int(11) | +-- | lastName | varchar(50) | +-- | firstName | varchar(50) | +-- | mobile | varchar(25) | +-- | code | int | +-- | jobTitle | varchar(50) | +-- | birth | date | +-- | Note | varchar(255) | +-- | Sex | varchar(5) | +-- +-- **要求4:**将表employees的mobile字段修改到code字段后面。 + alter table employees modify mobile varchar(25) after code; +-- **要求5:**将表employees的birth字段改名为birthday; + alter table employees change birth birthady date; +-- **要求6:**修改sex字段,数据类型为char(1)。 + alter table employees modify sex char(1); +-- **要求7:**删除字段note; + alter table employees drop Note; +-- **要求8:**增加字段名favoriate_activity,数据类型为varchar(100); + alter table employees add favoriate_activity varchar(100); +-- **要求9:**将表employees的名称修改为 employees_info + alter table employees rename employees_info; + +第二题 + +-- 1、创建数据库test02db + create database test02db charset utf8; +-- 2、创建表格pet + use test02db; + create table pet( + name varchar(20), + owner varchar(20), + species varchar(20), + sex char(1), + birth year, + death year + + ); +-- | 字段名 | 字段说明 | 数据类型 | +-- | ------- | -------- | ----------- | +-- | name | 宠物名称 | varchar(20) | +-- | owner | 宠物主人 | varchar(20) | +-- | species | 种类 | varchar(20) | +-- | sex | 性别 | char(1) | +-- | birth | 出生日期 | year | +-- | death | 死亡日期 | year | +-- +-- 3、添加记录 + +-- | name | owner | species | sex | birth | death | +-- | ------ | ------ | ------- | ---- | ----- | ----- | +-- | Fluffy | harold | Cat | f | 2003 | 2010 | +-- | Claws | gwen | Cat | m | 2004 | | +-- | Buffy | | Dog | f | 2009 | | +-- | Fang | benny | Dog | m | 2000 | | +-- | bowser | diane | Dog | m | 2003 | 2009 | +-- | Chirpy | | Bird | f | 2008 | | +desc pet; +update pet set owner='gwen' where birth='2004'; +insert into pet values('Fluffy','harold','Cat','f','2003','2010'), +('Claws','gwen','Cat','m',2004,null), +('Buffy',null,'Dog','f','2009',null), +('Fang','benny','Dog','m','2000',null), +('bowser','diane','Dog','m','2003','2009'), +('Chirpy',null,'Bird','f','2008',null); +-- 4、 添加字段主人的生日owner_birth。 +alter table pet add owner_birth year; +-- 5、 将名称为Claws的猫的主人改为kevin +update pet set name='kevin' where name='Claws'; +-- 6、 将没有死的狗的主人改为duck +update pet set owner='duck' where (death is NULL and species='Dog' and owner<>''); +-- 7、 查询没有主人的宠物的名字; +select name from pet where owner is null; +-- 8、 查询已经死了的cat的姓名,主人,以及去世时间; +select name,owner,death from pet where (species='Cat' and death<>''); +-- 9、 删除已经死亡的狗 + delete from pet where species='Dog' and death<>''; +-- 10、查询所有宠物信息 +select * from pet; +第三题 + +-- 1、创建数据库:test03_company +create database test03_company charset utf8; +-- ```sql +-- create database test03_company charset utf8; +-- ``` +-- +-- 2、在此数据库下创建如下3表,数据类型,宽度,是否为空根据实际情况自己定义。\ +-- A. 部门表(department):部门编号(depid),部门名称(depname),部门简介(deinfo);其中部门编号为主键。 +-- +use test03_company; +create table department( + depid int primary key, + depnmae varchar(10) not null unique key, + deinfo varchar(100) +); + + +-- B. 雇员表(employee):雇员编号(empid),姓名(name),性别(sex),职称(title),出生日期(birthday),所在部门编号(depid);其中 +-- +-- * ​ 雇员编号为主键; +-- * ​ 部门编号为外键,外键约束等级为(on update cascade 和on delete set null); +-- * ​ 性别默认为男; +create table employee( +empid int primary key, +name varchar(5) not null, +sex enum('男','女') not null default '男', +title varchar(10), +birthday date, +depid int, +foreign key (depid) references department(depid) on update cascade on delete set null +); +-- C. 工资表(salary):雇员编号(empid),基本工资(basesalary),职务工资(titlesalary),扣除(deduction)。其中雇员编号为主键。 +create table salary( + empid int primary key, + basesalary int, + titlesalary int, + deduction int + +); +-- 3、给工资表(salary)的雇员编号(empid)增加外键约束,外键约束等级为(on update cascade 和on delete cascade) +alter table salary add foreign key (empid) references employee(empid) on update cascade on delete cascade; +-- select * from information_schema.table_constraints WHERE table_name = 'salary'; +-- alter table salary drop foreign key salary_ibfk_1; +-- 4、添加数据如下: +-- +-- 部门表: +-- +-- | 部门编号 | 部门名称 | 部门简介 | +-- | -------- | -------- | ------------ | +-- | 111 | 生产部 | Null | +-- | 222 | 销售部 | Null | +-- | 333 | 人事部 | 人力资源管理 | + +insert into department values(111,'生产部',null),(222,'销售部',null),(333,'人事','人力资源管理'); +-- 雇员表: + +-- | 雇员编号 | 姓名 | 性别 | 职称 | 出生日期 | 所在部门编号 | +-- | -------- | ---- | ---- | ---------- | ---------- | ------------ | +-- | 1001 | 张三 | 男 | 高级工程师 | 1975-1-1 | 111 | +-- | 1002 | 李四 | 女 | 助工 | 1985-1-1 | 111 | +-- | 1003 | 王五 | 男 | 工程师 | 1978-11-11 | 222 | +-- | 1004 | 张六 | 男 | 工程师 | 1999-1-1 | 222 | +insert into employee values(1001,'张三','男','高级工程师','1975-1-1',111),(1002,'李四','女','助工','1985-1-1-',111), +(1003,'王五','男','工程师','1978-11-11',222), +(1004,'张六','男','工程师','1999-1-1',222); +-- 工资表: +-- +-- | 雇员编号 | 基本工资 | 职务工资 | 扣除 | +-- | -------- | -------- | -------- | ---- | +-- | 1001 | 2200 | 1100 | 200 | +-- | 1002 | 1200 | 200 | NULL | +-- | 1003 | 2900 | 700 | 200 | +-- | 1004 | 1950 | 700 | 150 | +insert into salary values(1001,2200,1100,200),(1002,1200,200,null),(1003,2900,700,200),(1004,1950,700,150); + +-- +-- +-- ## 第4题 +-- +-- 1、创建一个数据库:test04_school + create database test04_school charset utf8; + use test04_school; +-- 2、创建如下表格 +-- +-- 表1 Department表的定义 +-- +-- | **字段名** | **字段描述** | **数据类型** | **主键** | **外键** | **非空** | **唯一** | +-- | ---------- | ------------ | ------------ | -------- | -------- | -------- | -------- | +-- | DepNo | 部门号 | int(10) | 是 | 否 | 是 | 是 | +-- | DepName | 部门名称 | varchar(20) | 否 | 否 | 是 | 否 | +-- | DepNote | 部门备注 | Varchar(50) | 否 | 否 | 否 | 否 | + create table Department( + DepNo int primary key, + DepName varchar(20) not null, + DepNote varchar(50) + ); +-- 表2 Teacher表的定义 +-- +-- | **字段名** | **字段描述** | **数据类型** | **主键** | **外键** | **非空** | **唯一** | +-- | ---------- | ------------ | ------------ | -------- | -------- | -------- | -------- | +-- | Number | 教工号 | int | 是 | 否 | 是 | 是 | +-- | Name | 姓名 | varchar(30) | 否 | 否 | 是 | 否 | +-- | Sex | 性别 | varchar(4) | 否 | 否 | 否 | 否 | +-- | Birth | 出生日期 | date | 否 | 否 | 否 | 否 | +-- | DepNo | 部门号 | int | 否 | 是 | 否 | 否 | +-- | Salary | 工资 | float | 否 | 否 | 否 | 否 | +-- | Address | 家庭住址 | varchar(100) | 否 | 否 | 否 | 否 | +create table Teacher( +Number int primary key, +Name varchar(30) not null, +Sex varchar(4), +Birth date, +DepNo int, +foreign key (DepNo) references Department(DepNo) on update cascade on delete cascade, +Salary float, +Address varchar(100) +); +-- 3、添加记录 +-- +-- | **DepNo** | **DepName** | **DepNote** | +-- | --------- | ----------- | ------------------ | +-- | 601 | 软件技术系 | 软件技术等专业 | +-- | 602 | 网络技术系 | 多媒体技术等专业 | +-- | 603 | 艺术设计系 | 广告艺术设计等专业 | +-- | 604 | 管理工程系 | 连锁经营管理等专业 | + insert into Department values(601,'软件技术系','软件技术等专业'), + (602,'网络技术系','多媒体技术等专业'), + (603,'艺术设计系','广告艺术设计等专业'), + (604,'管理工程系','连锁经营管理等专业'); +-- | **Number** | **Name** | **Sex** | **Birth** | **DepNo** | **Salary** | **Address** | +-- | ---------- | -------- | ------- | ---------- | --------- | ---------- | ------------ | +-- | 2001 | Tom | 女 | 1970-01-10 | 602 | 4500 | 四川省绵阳市 | +-- | 2002 | Lucy | 男 | 1983-12-18 | 601 | 2500 | 北京市昌平区 | +-- | 2003 | Mike | 男 | 1990-06-01 | 604 | 1500 | 重庆市渝中区 | +-- | 2004 | James | 女 | 1980-10-20 | 602 | 3500 | 四川省成都市 | +-- | 2005 | Jack | 男 | 1975-05-30 | 603 | 1200 | 重庆市南岸区 | + insert into Teacher values(2001,'Tom','女','1970-01-10',602,4500,'四川省绵阳市'), + (2002,'Lucy','男','1983-12-18',601,2500,'北京市昌平区'), + (2003,'Mike','男','1990-06-01',604,1500,'重庆市渝中区'), + (2004,'James','女','1980-10-20',602,3500,'四川省成都市'), + (2005,'Jack','男','1975-05-30',603,1200,'重庆市南岸区'); +-- 4、用SELECT语句查询Teacher表的所有记录。 +SELECT * FROM Teacher; \ No newline at end of file -- Gitee From a5044f616726180cc9365a75002db30c776c0f41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=9C=87=E6=B4=8B?= <11785166+hzyai77@user.noreply.gitee.com> Date: Wed, 22 Feb 2023 14:12:25 +0000 Subject: [PATCH 06/12] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=2040?= =?UTF-8?q?=20=E9=9F=A9=E9=9C=87=E6=B4=8B=2020230220=E7=BA=A6=E6=9D=9F?= =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E5=92=8C=E7=AC=94=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 "40 \351\237\251\351\234\207\346\264\213 20230220\347\272\246\346\235\237\344\275\234\344\270\232\345\222\214\347\254\224\350\256\260/.keep" diff --git "a/40 \351\237\251\351\234\207\346\264\213 20230220\347\272\246\346\235\237\344\275\234\344\270\232\345\222\214\347\254\224\350\256\260/.keep" "b/40 \351\237\251\351\234\207\346\264\213 20230220\347\272\246\346\235\237\344\275\234\344\270\232\345\222\214\347\254\224\350\256\260/.keep" deleted file mode 100644 index e69de29..0000000 -- Gitee From 3fa51445cbef06405089b0cead3807b8cf3c8a7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=9C=87=E6=B4=8B?= <11785166+hzyai77@user.noreply.gitee.com> Date: Wed, 22 Feb 2023 14:20:06 +0000 Subject: [PATCH 07/12] =?UTF-8?q?=E6=96=B0=E5=BB=BA=2040=20=E9=9F=A9?= =?UTF-8?q?=E9=9C=87=E6=B4=8B.20230220=E7=BA=A6=E6=9D=9F=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E5=92=8C=E7=AC=94=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "40 \351\237\251\351\234\207\346\264\213.20230220\347\272\246\346\235\237\344\275\234\344\270\232\345\222\214\347\254\224\350\256\260/.keep" diff --git "a/40 \351\237\251\351\234\207\346\264\213.20230220\347\272\246\346\235\237\344\275\234\344\270\232\345\222\214\347\254\224\350\256\260/.keep" "b/40 \351\237\251\351\234\207\346\264\213.20230220\347\272\246\346\235\237\344\275\234\344\270\232\345\222\214\347\254\224\350\256\260/.keep" new file mode 100644 index 0000000..e69de29 -- Gitee From 035027220c3abe4f34cc6364a892bbcff674e0cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=9C=87=E6=B4=8B?= <11785166+hzyai77@user.noreply.gitee.com> Date: Wed, 22 Feb 2023 14:21:22 +0000 Subject: [PATCH 08/12] =?UTF-8?q?=E9=87=8D=E5=91=BD=E5=90=8D=2040=20?= =?UTF-8?q?=E9=9F=A9=E9=9C=87=E6=B4=8B.20230220=E7=BA=A6=E6=9D=9F=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A=E5=92=8C=E7=AC=94=E8=AE=B0=20=E4=B8=BA=2040=20?= =?UTF-8?q?=E9=9F=A9=E9=9C=87=E6=B4=8B.=E4=BD=9C=E4=B8=9A=E5=92=8C?= =?UTF-8?q?=E7=AC=94=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename "40 \351\237\251\351\234\207\346\264\213.20230220\347\272\246\346\235\237\344\275\234\344\270\232\345\222\214\347\254\224\350\256\260/.keep" => "40 \351\237\251\351\234\207\346\264\213.\344\275\234\344\270\232\345\222\214\347\254\224\350\256\260/.keep" (100%) diff --git "a/40 \351\237\251\351\234\207\346\264\213.20230220\347\272\246\346\235\237\344\275\234\344\270\232\345\222\214\347\254\224\350\256\260/.keep" "b/40 \351\237\251\351\234\207\346\264\213.\344\275\234\344\270\232\345\222\214\347\254\224\350\256\260/.keep" similarity index 100% rename from "40 \351\237\251\351\234\207\346\264\213.20230220\347\272\246\346\235\237\344\275\234\344\270\232\345\222\214\347\254\224\350\256\260/.keep" rename to "40 \351\237\251\351\234\207\346\264\213.\344\275\234\344\270\232\345\222\214\347\254\224\350\256\260/.keep" -- Gitee From 2c301290bfac0c2cec96b09c15b99eb05d7dd12b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=9C=87=E6=B4=8B?= <11785166+hzyai77@user.noreply.gitee.com> Date: Wed, 22 Feb 2023 14:21:30 +0000 Subject: [PATCH 09/12] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=2040?= =?UTF-8?q?=20=E9=9F=A9=E9=9C=87=E6=B4=8B-20230220=20=E7=BA=A6=E6=9D=9F?= =?UTF-8?q?=E7=9A=84=E5=AD=A6=E4=B9=A0=E4=B8=8E=E4=BD=9C=E4=B8=9A.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...40\344\270\216\344\275\234\344\270\232.md" | 305 ------------------ 1 file changed, 305 deletions(-) delete mode 100644 "40 \351\237\251\351\234\207\346\264\213-20230220 \347\272\246\346\235\237\347\232\204\345\255\246\344\271\240\344\270\216\344\275\234\344\270\232.md" diff --git "a/40 \351\237\251\351\234\207\346\264\213-20230220 \347\272\246\346\235\237\347\232\204\345\255\246\344\271\240\344\270\216\344\275\234\344\270\232.md" "b/40 \351\237\251\351\234\207\346\264\213-20230220 \347\272\246\346\235\237\347\232\204\345\255\246\344\271\240\344\270\216\344\275\234\344\270\232.md" deleted file mode 100644 index 726e517..0000000 --- "a/40 \351\237\251\351\234\207\346\264\213-20230220 \347\272\246\346\235\237\347\232\204\345\255\246\344\271\240\344\270\216\344\275\234\344\270\232.md" +++ /dev/null @@ -1,305 +0,0 @@ -笔记 -学习 -主键,外键,默认值,自增,唯一约束,非空 - -主键:primary key (非空 唯一) - -cr ta 表格名( - 字段 类型 primary key - 或者 primary key(字段1,字段2) - 或primary key(字段) -); -#建表后增加主键: -alter table 表名 add primary key(字段 (可以多个)) -#删除: -alter table 表名 drop primary key; -外键:foreign key - -cr ta 表格名( - 字段 类型, - foreign key (字段) references 主表(字段); (no update/delete x)外键等级 - -); -默认值:default - -cr ta 表格名( - 字段 类型 default 默认值 -); -#默认值:一般不和唯一约束和主键一起加; - -#建表后增加默认值: -alter table 表名 modify default 默认值 (not null); 看有没有加 -#删除 -alter table 表名 modify 字段名 数据类型 (not null); 看有没有加 -自增:auto_increment - -唯一约束:unique key - -非空:not null - -cr ta 表格名( - 字段 类型 not null -); -2.作业 -第一题 - --- 1、创建数据库test01_company -create database test01_company charset utf8; --- 2、创建表格offices -use test01_company; -create table offices( - officeCode int, - city varchar(30), - address varchar(50), - country varchar(50), - postalCode varchar(25) - -); --- --- | 字段名 | 数据类型 | --- | ---------- | ----------- | --- | officeCode | int | --- | city | varchar(30) | --- | address | varchar(50) | --- | country | varchar(50) | --- | postalCode | varchar(25) | --- --- 3、创建表格employees - create table employees( - empNum int, - lastName varchar(50), - firstName varchar(50), - mobile varchar(50), - code int, - jobTitle varchar(50), - birth date, - Note varchar(255), - Sex varchar(5) - ); - --- | 字段名 | 数据类型 | --- | --------- | ------------- | --- | empNum | int(11) | --- | lastName | varchar(50) | --- | firstName | varchar(50) | --- | mobile | varchar(25) | --- | code | int | --- | jobTitle | varchar(50) | --- | birth | date | --- | Note | varchar(255) | --- | Sex | varchar(5) | --- --- **要求4:**将表employees的mobile字段修改到code字段后面。 - alter table employees modify mobile varchar(25) after code; --- **要求5:**将表employees的birth字段改名为birthday; - alter table employees change birth birthady date; --- **要求6:**修改sex字段,数据类型为char(1)。 - alter table employees modify sex char(1); --- **要求7:**删除字段note; - alter table employees drop Note; --- **要求8:**增加字段名favoriate_activity,数据类型为varchar(100); - alter table employees add favoriate_activity varchar(100); --- **要求9:**将表employees的名称修改为 employees_info - alter table employees rename employees_info; - -第二题 - --- 1、创建数据库test02db - create database test02db charset utf8; --- 2、创建表格pet - use test02db; - create table pet( - name varchar(20), - owner varchar(20), - species varchar(20), - sex char(1), - birth year, - death year - - ); --- | 字段名 | 字段说明 | 数据类型 | --- | ------- | -------- | ----------- | --- | name | 宠物名称 | varchar(20) | --- | owner | 宠物主人 | varchar(20) | --- | species | 种类 | varchar(20) | --- | sex | 性别 | char(1) | --- | birth | 出生日期 | year | --- | death | 死亡日期 | year | --- --- 3、添加记录 - --- | name | owner | species | sex | birth | death | --- | ------ | ------ | ------- | ---- | ----- | ----- | --- | Fluffy | harold | Cat | f | 2003 | 2010 | --- | Claws | gwen | Cat | m | 2004 | | --- | Buffy | | Dog | f | 2009 | | --- | Fang | benny | Dog | m | 2000 | | --- | bowser | diane | Dog | m | 2003 | 2009 | --- | Chirpy | | Bird | f | 2008 | | -desc pet; -update pet set owner='gwen' where birth='2004'; -insert into pet values('Fluffy','harold','Cat','f','2003','2010'), -('Claws','gwen','Cat','m',2004,null), -('Buffy',null,'Dog','f','2009',null), -('Fang','benny','Dog','m','2000',null), -('bowser','diane','Dog','m','2003','2009'), -('Chirpy',null,'Bird','f','2008',null); --- 4、 添加字段主人的生日owner_birth。 -alter table pet add owner_birth year; --- 5、 将名称为Claws的猫的主人改为kevin -update pet set name='kevin' where name='Claws'; --- 6、 将没有死的狗的主人改为duck -update pet set owner='duck' where (death is NULL and species='Dog' and owner<>''); --- 7、 查询没有主人的宠物的名字; -select name from pet where owner is null; --- 8、 查询已经死了的cat的姓名,主人,以及去世时间; -select name,owner,death from pet where (species='Cat' and death<>''); --- 9、 删除已经死亡的狗 - delete from pet where species='Dog' and death<>''; --- 10、查询所有宠物信息 -select * from pet; -第三题 - --- 1、创建数据库:test03_company -create database test03_company charset utf8; --- ```sql --- create database test03_company charset utf8; --- ``` --- --- 2、在此数据库下创建如下3表,数据类型,宽度,是否为空根据实际情况自己定义。\ --- A. 部门表(department):部门编号(depid),部门名称(depname),部门简介(deinfo);其中部门编号为主键。 --- -use test03_company; -create table department( - depid int primary key, - depnmae varchar(10) not null unique key, - deinfo varchar(100) -); - - --- B. 雇员表(employee):雇员编号(empid),姓名(name),性别(sex),职称(title),出生日期(birthday),所在部门编号(depid);其中 --- --- * ​ 雇员编号为主键; --- * ​ 部门编号为外键,外键约束等级为(on update cascade 和on delete set null); --- * ​ 性别默认为男; -create table employee( -empid int primary key, -name varchar(5) not null, -sex enum('男','女') not null default '男', -title varchar(10), -birthday date, -depid int, -foreign key (depid) references department(depid) on update cascade on delete set null -); --- C. 工资表(salary):雇员编号(empid),基本工资(basesalary),职务工资(titlesalary),扣除(deduction)。其中雇员编号为主键。 -create table salary( - empid int primary key, - basesalary int, - titlesalary int, - deduction int - -); --- 3、给工资表(salary)的雇员编号(empid)增加外键约束,外键约束等级为(on update cascade 和on delete cascade) -alter table salary add foreign key (empid) references employee(empid) on update cascade on delete cascade; --- select * from information_schema.table_constraints WHERE table_name = 'salary'; --- alter table salary drop foreign key salary_ibfk_1; --- 4、添加数据如下: --- --- 部门表: --- --- | 部门编号 | 部门名称 | 部门简介 | --- | -------- | -------- | ------------ | --- | 111 | 生产部 | Null | --- | 222 | 销售部 | Null | --- | 333 | 人事部 | 人力资源管理 | - -insert into department values(111,'生产部',null),(222,'销售部',null),(333,'人事','人力资源管理'); --- 雇员表: - --- | 雇员编号 | 姓名 | 性别 | 职称 | 出生日期 | 所在部门编号 | --- | -------- | ---- | ---- | ---------- | ---------- | ------------ | --- | 1001 | 张三 | 男 | 高级工程师 | 1975-1-1 | 111 | --- | 1002 | 李四 | 女 | 助工 | 1985-1-1 | 111 | --- | 1003 | 王五 | 男 | 工程师 | 1978-11-11 | 222 | --- | 1004 | 张六 | 男 | 工程师 | 1999-1-1 | 222 | -insert into employee values(1001,'张三','男','高级工程师','1975-1-1',111),(1002,'李四','女','助工','1985-1-1-',111), -(1003,'王五','男','工程师','1978-11-11',222), -(1004,'张六','男','工程师','1999-1-1',222); --- 工资表: --- --- | 雇员编号 | 基本工资 | 职务工资 | 扣除 | --- | -------- | -------- | -------- | ---- | --- | 1001 | 2200 | 1100 | 200 | --- | 1002 | 1200 | 200 | NULL | --- | 1003 | 2900 | 700 | 200 | --- | 1004 | 1950 | 700 | 150 | -insert into salary values(1001,2200,1100,200),(1002,1200,200,null),(1003,2900,700,200),(1004,1950,700,150); - --- --- --- ## 第4题 --- --- 1、创建一个数据库:test04_school - create database test04_school charset utf8; - use test04_school; --- 2、创建如下表格 --- --- 表1 Department表的定义 --- --- | **字段名** | **字段描述** | **数据类型** | **主键** | **外键** | **非空** | **唯一** | --- | ---------- | ------------ | ------------ | -------- | -------- | -------- | -------- | --- | DepNo | 部门号 | int(10) | 是 | 否 | 是 | 是 | --- | DepName | 部门名称 | varchar(20) | 否 | 否 | 是 | 否 | --- | DepNote | 部门备注 | Varchar(50) | 否 | 否 | 否 | 否 | - create table Department( - DepNo int primary key, - DepName varchar(20) not null, - DepNote varchar(50) - ); --- 表2 Teacher表的定义 --- --- | **字段名** | **字段描述** | **数据类型** | **主键** | **外键** | **非空** | **唯一** | --- | ---------- | ------------ | ------------ | -------- | -------- | -------- | -------- | --- | Number | 教工号 | int | 是 | 否 | 是 | 是 | --- | Name | 姓名 | varchar(30) | 否 | 否 | 是 | 否 | --- | Sex | 性别 | varchar(4) | 否 | 否 | 否 | 否 | --- | Birth | 出生日期 | date | 否 | 否 | 否 | 否 | --- | DepNo | 部门号 | int | 否 | 是 | 否 | 否 | --- | Salary | 工资 | float | 否 | 否 | 否 | 否 | --- | Address | 家庭住址 | varchar(100) | 否 | 否 | 否 | 否 | -create table Teacher( -Number int primary key, -Name varchar(30) not null, -Sex varchar(4), -Birth date, -DepNo int, -foreign key (DepNo) references Department(DepNo) on update cascade on delete cascade, -Salary float, -Address varchar(100) -); --- 3、添加记录 --- --- | **DepNo** | **DepName** | **DepNote** | --- | --------- | ----------- | ------------------ | --- | 601 | 软件技术系 | 软件技术等专业 | --- | 602 | 网络技术系 | 多媒体技术等专业 | --- | 603 | 艺术设计系 | 广告艺术设计等专业 | --- | 604 | 管理工程系 | 连锁经营管理等专业 | - insert into Department values(601,'软件技术系','软件技术等专业'), - (602,'网络技术系','多媒体技术等专业'), - (603,'艺术设计系','广告艺术设计等专业'), - (604,'管理工程系','连锁经营管理等专业'); --- | **Number** | **Name** | **Sex** | **Birth** | **DepNo** | **Salary** | **Address** | --- | ---------- | -------- | ------- | ---------- | --------- | ---------- | ------------ | --- | 2001 | Tom | 女 | 1970-01-10 | 602 | 4500 | 四川省绵阳市 | --- | 2002 | Lucy | 男 | 1983-12-18 | 601 | 2500 | 北京市昌平区 | --- | 2003 | Mike | 男 | 1990-06-01 | 604 | 1500 | 重庆市渝中区 | --- | 2004 | James | 女 | 1980-10-20 | 602 | 3500 | 四川省成都市 | --- | 2005 | Jack | 男 | 1975-05-30 | 603 | 1200 | 重庆市南岸区 | - insert into Teacher values(2001,'Tom','女','1970-01-10',602,4500,'四川省绵阳市'), - (2002,'Lucy','男','1983-12-18',601,2500,'北京市昌平区'), - (2003,'Mike','男','1990-06-01',604,1500,'重庆市渝中区'), - (2004,'James','女','1980-10-20',602,3500,'四川省成都市'), - (2005,'Jack','男','1975-05-30',603,1200,'重庆市南岸区'); --- 4、用SELECT语句查询Teacher表的所有记录。 -SELECT * FROM Teacher; \ No newline at end of file -- Gitee From cbfdb55a0f6661f7e1156babf69b84e552ef81e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=9C=87=E6=B4=8B?= <11785166+hzyai77@user.noreply.gitee.com> Date: Wed, 22 Feb 2023 14:21:53 +0000 Subject: [PATCH 10/12] =?UTF-8?q?40=20=E9=9F=A9=E9=9C=87=E6=B4=8B=20202302?= =?UTF-8?q?20=E7=BA=A6=E6=9D=9F=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 韩震洋 <11785166+hzyai77@user.noreply.gitee.com> --- ...40\344\270\216\344\275\234\344\270\232.md" | 305 ++++++++++++++++++ 1 file changed, 305 insertions(+) create mode 100644 "40 \351\237\251\351\234\207\346\264\213.\344\275\234\344\270\232\345\222\214\347\254\224\350\256\260/40 \351\237\251\351\234\207\346\264\213-20230220 \347\272\246\346\235\237\347\232\204\345\255\246\344\271\240\344\270\216\344\275\234\344\270\232.md" diff --git "a/40 \351\237\251\351\234\207\346\264\213.\344\275\234\344\270\232\345\222\214\347\254\224\350\256\260/40 \351\237\251\351\234\207\346\264\213-20230220 \347\272\246\346\235\237\347\232\204\345\255\246\344\271\240\344\270\216\344\275\234\344\270\232.md" "b/40 \351\237\251\351\234\207\346\264\213.\344\275\234\344\270\232\345\222\214\347\254\224\350\256\260/40 \351\237\251\351\234\207\346\264\213-20230220 \347\272\246\346\235\237\347\232\204\345\255\246\344\271\240\344\270\216\344\275\234\344\270\232.md" new file mode 100644 index 0000000..726e517 --- /dev/null +++ "b/40 \351\237\251\351\234\207\346\264\213.\344\275\234\344\270\232\345\222\214\347\254\224\350\256\260/40 \351\237\251\351\234\207\346\264\213-20230220 \347\272\246\346\235\237\347\232\204\345\255\246\344\271\240\344\270\216\344\275\234\344\270\232.md" @@ -0,0 +1,305 @@ +笔记 +学习 +主键,外键,默认值,自增,唯一约束,非空 + +主键:primary key (非空 唯一) + +cr ta 表格名( + 字段 类型 primary key + 或者 primary key(字段1,字段2) + 或primary key(字段) +); +#建表后增加主键: +alter table 表名 add primary key(字段 (可以多个)) +#删除: +alter table 表名 drop primary key; +外键:foreign key + +cr ta 表格名( + 字段 类型, + foreign key (字段) references 主表(字段); (no update/delete x)外键等级 + +); +默认值:default + +cr ta 表格名( + 字段 类型 default 默认值 +); +#默认值:一般不和唯一约束和主键一起加; + +#建表后增加默认值: +alter table 表名 modify default 默认值 (not null); 看有没有加 +#删除 +alter table 表名 modify 字段名 数据类型 (not null); 看有没有加 +自增:auto_increment + +唯一约束:unique key + +非空:not null + +cr ta 表格名( + 字段 类型 not null +); +2.作业 +第一题 + +-- 1、创建数据库test01_company +create database test01_company charset utf8; +-- 2、创建表格offices +use test01_company; +create table offices( + officeCode int, + city varchar(30), + address varchar(50), + country varchar(50), + postalCode varchar(25) + +); +-- +-- | 字段名 | 数据类型 | +-- | ---------- | ----------- | +-- | officeCode | int | +-- | city | varchar(30) | +-- | address | varchar(50) | +-- | country | varchar(50) | +-- | postalCode | varchar(25) | +-- +-- 3、创建表格employees + create table employees( + empNum int, + lastName varchar(50), + firstName varchar(50), + mobile varchar(50), + code int, + jobTitle varchar(50), + birth date, + Note varchar(255), + Sex varchar(5) + ); + +-- | 字段名 | 数据类型 | +-- | --------- | ------------- | +-- | empNum | int(11) | +-- | lastName | varchar(50) | +-- | firstName | varchar(50) | +-- | mobile | varchar(25) | +-- | code | int | +-- | jobTitle | varchar(50) | +-- | birth | date | +-- | Note | varchar(255) | +-- | Sex | varchar(5) | +-- +-- **要求4:**将表employees的mobile字段修改到code字段后面。 + alter table employees modify mobile varchar(25) after code; +-- **要求5:**将表employees的birth字段改名为birthday; + alter table employees change birth birthady date; +-- **要求6:**修改sex字段,数据类型为char(1)。 + alter table employees modify sex char(1); +-- **要求7:**删除字段note; + alter table employees drop Note; +-- **要求8:**增加字段名favoriate_activity,数据类型为varchar(100); + alter table employees add favoriate_activity varchar(100); +-- **要求9:**将表employees的名称修改为 employees_info + alter table employees rename employees_info; + +第二题 + +-- 1、创建数据库test02db + create database test02db charset utf8; +-- 2、创建表格pet + use test02db; + create table pet( + name varchar(20), + owner varchar(20), + species varchar(20), + sex char(1), + birth year, + death year + + ); +-- | 字段名 | 字段说明 | 数据类型 | +-- | ------- | -------- | ----------- | +-- | name | 宠物名称 | varchar(20) | +-- | owner | 宠物主人 | varchar(20) | +-- | species | 种类 | varchar(20) | +-- | sex | 性别 | char(1) | +-- | birth | 出生日期 | year | +-- | death | 死亡日期 | year | +-- +-- 3、添加记录 + +-- | name | owner | species | sex | birth | death | +-- | ------ | ------ | ------- | ---- | ----- | ----- | +-- | Fluffy | harold | Cat | f | 2003 | 2010 | +-- | Claws | gwen | Cat | m | 2004 | | +-- | Buffy | | Dog | f | 2009 | | +-- | Fang | benny | Dog | m | 2000 | | +-- | bowser | diane | Dog | m | 2003 | 2009 | +-- | Chirpy | | Bird | f | 2008 | | +desc pet; +update pet set owner='gwen' where birth='2004'; +insert into pet values('Fluffy','harold','Cat','f','2003','2010'), +('Claws','gwen','Cat','m',2004,null), +('Buffy',null,'Dog','f','2009',null), +('Fang','benny','Dog','m','2000',null), +('bowser','diane','Dog','m','2003','2009'), +('Chirpy',null,'Bird','f','2008',null); +-- 4、 添加字段主人的生日owner_birth。 +alter table pet add owner_birth year; +-- 5、 将名称为Claws的猫的主人改为kevin +update pet set name='kevin' where name='Claws'; +-- 6、 将没有死的狗的主人改为duck +update pet set owner='duck' where (death is NULL and species='Dog' and owner<>''); +-- 7、 查询没有主人的宠物的名字; +select name from pet where owner is null; +-- 8、 查询已经死了的cat的姓名,主人,以及去世时间; +select name,owner,death from pet where (species='Cat' and death<>''); +-- 9、 删除已经死亡的狗 + delete from pet where species='Dog' and death<>''; +-- 10、查询所有宠物信息 +select * from pet; +第三题 + +-- 1、创建数据库:test03_company +create database test03_company charset utf8; +-- ```sql +-- create database test03_company charset utf8; +-- ``` +-- +-- 2、在此数据库下创建如下3表,数据类型,宽度,是否为空根据实际情况自己定义。\ +-- A. 部门表(department):部门编号(depid),部门名称(depname),部门简介(deinfo);其中部门编号为主键。 +-- +use test03_company; +create table department( + depid int primary key, + depnmae varchar(10) not null unique key, + deinfo varchar(100) +); + + +-- B. 雇员表(employee):雇员编号(empid),姓名(name),性别(sex),职称(title),出生日期(birthday),所在部门编号(depid);其中 +-- +-- * ​ 雇员编号为主键; +-- * ​ 部门编号为外键,外键约束等级为(on update cascade 和on delete set null); +-- * ​ 性别默认为男; +create table employee( +empid int primary key, +name varchar(5) not null, +sex enum('男','女') not null default '男', +title varchar(10), +birthday date, +depid int, +foreign key (depid) references department(depid) on update cascade on delete set null +); +-- C. 工资表(salary):雇员编号(empid),基本工资(basesalary),职务工资(titlesalary),扣除(deduction)。其中雇员编号为主键。 +create table salary( + empid int primary key, + basesalary int, + titlesalary int, + deduction int + +); +-- 3、给工资表(salary)的雇员编号(empid)增加外键约束,外键约束等级为(on update cascade 和on delete cascade) +alter table salary add foreign key (empid) references employee(empid) on update cascade on delete cascade; +-- select * from information_schema.table_constraints WHERE table_name = 'salary'; +-- alter table salary drop foreign key salary_ibfk_1; +-- 4、添加数据如下: +-- +-- 部门表: +-- +-- | 部门编号 | 部门名称 | 部门简介 | +-- | -------- | -------- | ------------ | +-- | 111 | 生产部 | Null | +-- | 222 | 销售部 | Null | +-- | 333 | 人事部 | 人力资源管理 | + +insert into department values(111,'生产部',null),(222,'销售部',null),(333,'人事','人力资源管理'); +-- 雇员表: + +-- | 雇员编号 | 姓名 | 性别 | 职称 | 出生日期 | 所在部门编号 | +-- | -------- | ---- | ---- | ---------- | ---------- | ------------ | +-- | 1001 | 张三 | 男 | 高级工程师 | 1975-1-1 | 111 | +-- | 1002 | 李四 | 女 | 助工 | 1985-1-1 | 111 | +-- | 1003 | 王五 | 男 | 工程师 | 1978-11-11 | 222 | +-- | 1004 | 张六 | 男 | 工程师 | 1999-1-1 | 222 | +insert into employee values(1001,'张三','男','高级工程师','1975-1-1',111),(1002,'李四','女','助工','1985-1-1-',111), +(1003,'王五','男','工程师','1978-11-11',222), +(1004,'张六','男','工程师','1999-1-1',222); +-- 工资表: +-- +-- | 雇员编号 | 基本工资 | 职务工资 | 扣除 | +-- | -------- | -------- | -------- | ---- | +-- | 1001 | 2200 | 1100 | 200 | +-- | 1002 | 1200 | 200 | NULL | +-- | 1003 | 2900 | 700 | 200 | +-- | 1004 | 1950 | 700 | 150 | +insert into salary values(1001,2200,1100,200),(1002,1200,200,null),(1003,2900,700,200),(1004,1950,700,150); + +-- +-- +-- ## 第4题 +-- +-- 1、创建一个数据库:test04_school + create database test04_school charset utf8; + use test04_school; +-- 2、创建如下表格 +-- +-- 表1 Department表的定义 +-- +-- | **字段名** | **字段描述** | **数据类型** | **主键** | **外键** | **非空** | **唯一** | +-- | ---------- | ------------ | ------------ | -------- | -------- | -------- | -------- | +-- | DepNo | 部门号 | int(10) | 是 | 否 | 是 | 是 | +-- | DepName | 部门名称 | varchar(20) | 否 | 否 | 是 | 否 | +-- | DepNote | 部门备注 | Varchar(50) | 否 | 否 | 否 | 否 | + create table Department( + DepNo int primary key, + DepName varchar(20) not null, + DepNote varchar(50) + ); +-- 表2 Teacher表的定义 +-- +-- | **字段名** | **字段描述** | **数据类型** | **主键** | **外键** | **非空** | **唯一** | +-- | ---------- | ------------ | ------------ | -------- | -------- | -------- | -------- | +-- | Number | 教工号 | int | 是 | 否 | 是 | 是 | +-- | Name | 姓名 | varchar(30) | 否 | 否 | 是 | 否 | +-- | Sex | 性别 | varchar(4) | 否 | 否 | 否 | 否 | +-- | Birth | 出生日期 | date | 否 | 否 | 否 | 否 | +-- | DepNo | 部门号 | int | 否 | 是 | 否 | 否 | +-- | Salary | 工资 | float | 否 | 否 | 否 | 否 | +-- | Address | 家庭住址 | varchar(100) | 否 | 否 | 否 | 否 | +create table Teacher( +Number int primary key, +Name varchar(30) not null, +Sex varchar(4), +Birth date, +DepNo int, +foreign key (DepNo) references Department(DepNo) on update cascade on delete cascade, +Salary float, +Address varchar(100) +); +-- 3、添加记录 +-- +-- | **DepNo** | **DepName** | **DepNote** | +-- | --------- | ----------- | ------------------ | +-- | 601 | 软件技术系 | 软件技术等专业 | +-- | 602 | 网络技术系 | 多媒体技术等专业 | +-- | 603 | 艺术设计系 | 广告艺术设计等专业 | +-- | 604 | 管理工程系 | 连锁经营管理等专业 | + insert into Department values(601,'软件技术系','软件技术等专业'), + (602,'网络技术系','多媒体技术等专业'), + (603,'艺术设计系','广告艺术设计等专业'), + (604,'管理工程系','连锁经营管理等专业'); +-- | **Number** | **Name** | **Sex** | **Birth** | **DepNo** | **Salary** | **Address** | +-- | ---------- | -------- | ------- | ---------- | --------- | ---------- | ------------ | +-- | 2001 | Tom | 女 | 1970-01-10 | 602 | 4500 | 四川省绵阳市 | +-- | 2002 | Lucy | 男 | 1983-12-18 | 601 | 2500 | 北京市昌平区 | +-- | 2003 | Mike | 男 | 1990-06-01 | 604 | 1500 | 重庆市渝中区 | +-- | 2004 | James | 女 | 1980-10-20 | 602 | 3500 | 四川省成都市 | +-- | 2005 | Jack | 男 | 1975-05-30 | 603 | 1200 | 重庆市南岸区 | + insert into Teacher values(2001,'Tom','女','1970-01-10',602,4500,'四川省绵阳市'), + (2002,'Lucy','男','1983-12-18',601,2500,'北京市昌平区'), + (2003,'Mike','男','1990-06-01',604,1500,'重庆市渝中区'), + (2004,'James','女','1980-10-20',602,3500,'四川省成都市'), + (2005,'Jack','男','1975-05-30',603,1200,'重庆市南岸区'); +-- 4、用SELECT语句查询Teacher表的所有记录。 +SELECT * FROM Teacher; \ No newline at end of file -- Gitee From a90b2ced8d4ab8e5918bd24bc8fba1aed4203b61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=9C=87=E6=B4=8B?= <11785166+hzyai77@user.noreply.gitee.com> Date: Wed, 22 Feb 2023 14:22:25 +0000 Subject: [PATCH 11/12] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=2040?= =?UTF-8?q?=20=E9=9F=A9=E9=9C=87=E6=B4=8B.=E4=BD=9C=E4=B8=9A=E5=92=8C?= =?UTF-8?q?=E7=AC=94=E8=AE=B0/.keep?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 "40 \351\237\251\351\234\207\346\264\213.\344\275\234\344\270\232\345\222\214\347\254\224\350\256\260/.keep" diff --git "a/40 \351\237\251\351\234\207\346\264\213.\344\275\234\344\270\232\345\222\214\347\254\224\350\256\260/.keep" "b/40 \351\237\251\351\234\207\346\264\213.\344\275\234\344\270\232\345\222\214\347\254\224\350\256\260/.keep" deleted file mode 100644 index e69de29..0000000 -- Gitee From d0151d4eca6103680b19e7a4aeb2084c0cc426ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=9C=87=E6=B4=8B?= <11785166+hzyai77@user.noreply.gitee.com> Date: Wed, 22 Feb 2023 14:26:43 +0000 Subject: [PATCH 12/12] =?UTF-8?q?40=20=E9=9F=A9=E9=9C=87=E6=B4=8B=20202302?= =?UTF-8?q?20=E6=95=B0=E6=8D=AE=E7=B1=BB=E5=9E=8B=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E4=B8=8E=E7=AC=94=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 韩震洋 <11785166+hzyai77@user.noreply.gitee.com> --- ...32\344\270\216\347\254\224\350\256\260.md" | 283 ++++++++++++++++++ 1 file changed, 283 insertions(+) create mode 100644 "40 \351\237\251\351\234\207\346\264\213.\344\275\234\344\270\232\345\222\214\347\254\224\350\256\260/40 \351\237\251\351\234\207\346\264\213 20230221 \346\225\260\346\215\256\347\261\273\345\236\213\344\275\234\344\270\232\344\270\216\347\254\224\350\256\260.md" diff --git "a/40 \351\237\251\351\234\207\346\264\213.\344\275\234\344\270\232\345\222\214\347\254\224\350\256\260/40 \351\237\251\351\234\207\346\264\213 20230221 \346\225\260\346\215\256\347\261\273\345\236\213\344\275\234\344\270\232\344\270\216\347\254\224\350\256\260.md" "b/40 \351\237\251\351\234\207\346\264\213.\344\275\234\344\270\232\345\222\214\347\254\224\350\256\260/40 \351\237\251\351\234\207\346\264\213 20230221 \346\225\260\346\215\256\347\261\273\345\236\213\344\275\234\344\270\232\344\270\216\347\254\224\350\256\260.md" new file mode 100644 index 0000000..dba9d2f --- /dev/null +++ "b/40 \351\237\251\351\234\207\346\264\213.\344\275\234\344\270\232\345\222\214\347\254\224\350\256\260/40 \351\237\251\351\234\207\346\264\213 20230221 \346\225\260\346\215\256\347\261\273\345\236\213\344\275\234\344\270\232\344\270\216\347\254\224\350\256\260.md" @@ -0,0 +1,283 @@ +笔记 +SQL语句 +DDL(数据定义语言): create(创建) alter(修改) drop(删除) show(展示) +DML(数据操作语言): insert(增加) delete(删除) update(修改) +DQL(数据查询语言): select(查询) +DCL(数据控制语言): grant(授权) commit(确认) rollback(回滚) +增加表字段: +alter table 表名称 add 字段名 数据类型; +删除表字段: +alter table 表名称 drop 字段名; +修改字段名称: +alter table 表名称 change 旧字段名 新字段名 数据类型; +修改数据类型: +alter table 表名称 modify 字段名 新数据类型; +修改字段顺序: +alter table 表名称 modify 字段名1 数据类型 after 字段名2;(字段1移动到字段2后面) +alter table 表名称 modify 字段名 数据类型 first;(将字段移动到第一位) +修改表名称 +alter table 旧标明 rename to 新表名; +删除列的定义 +alter table 表名 drop 字段名; +修改表数据(无条件) +update 表名 set 字段名 = 新值; +修改表数据(指定条件) +update 表名 set 字段名 = 新值 where 条件(如 name = 'XXX'); +update 表名 set 字段名 = 新值 where 条件字段名 in (如 where name in('XXX','XXX')) +删除表数据(无条件) +delete from 表名; +删除表数据(指定条件 行) +delete from 表名 where 条件(如 id = ); +数据类型 + 整形:int (int(M):无意义) + int(M) zerofill:不足M位用0补足, + 浮点型:float:小数、单浮点型 + float(M,N):M表示整个数字的长度,N表示小数部分的长度 + 双浮点型: double + double(M,N):与float相同 + 精准型:decimal + 定长字符串:char + 可变字符串:varchar(M) +2、作业 +-- ## 第1题 +drop database test01_market; +-- 1、创建数据库test01_market +create database test01_market charset utf8; +-- 2、创建表格customers +use test01_market; +-- | 字段名 | 数据类型 | +-- | --------- | ----------- | +-- | c_num | int(11) | +-- | c_name | varchar(50) | +-- | c_contact | varchar(50) | +-- | c_city | varchar(50) | +-- | c_birth | date | +create table customers( +c_num int, +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); +alter table customers modify 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题 +-- drop database test02_library; +-- 1、创建数据库test02_library +create database test02_library charset utf8; +-- 2、创建表格books +use test02_library; +-- | 字段名 | 字段说明 | 数据类型 | 允许为空 | 唯一 | +-- | ------- | -------- | ------------- | -------- | ---- | +-- | b_id | 书编号 | int(11) | 否 | 是 | +-- | b_name | 书名 | varchar(50) | 否 | 否 | +-- | authors | 作者 | varchar(100) | 否 | 否 | +-- | price | 价格 | float | 否 | 否 | +-- | pubdate | 出版日期 | year | 否 | 否 | +-- | note | 说明 | varchar(100) | 是 | 否 | +-- | num | 库存 | int(11) | 否 | 否 | +create table books( +b_id int not null 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 not null comment '库存' +); +-- 3、向books表中插入记录 + +-- 1) 指定所有字段名称插入第一条记录 +-- +-- 2)不指定字段名称插入第二记录 + +-- 3)同时插入多条记录(剩下的所有记录) +-- +-- | 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 | +insert into books(b_id,b_name,`authors`,price,pubdate,note,num) values ( +1,'Tal of AAA','Dickes',23,'1995','novel',11 +); +insert into books values( +2,'EmmaT','Jane lura',35,'1993','joke',22 +); +insert into books values(3,'Story of Jane','Jant 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'; +select * from books; + + +-- ## 第3题 +-- drop database test03_bookstore; +-- 1、创建数据库test03_bookstore +create database test03_bookstore charset utf8; +-- 2、创建book表 +use test03_bookstore; +-- ```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 | | +-- +----------+--------------+------+-----+---------+----------------+ +-- ``` +-- drop table book; +create table book( +id int not null auto_increment, +title varchar(100) not null, +author varchar(100), +price double(11,2) not null, +sales int not null, +stock int not null, +img_path varchar(100) not null, +primary key(`id`) +); +-- 尝试添加部分模拟数据,参考示例如下: +-- +-- ```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 | +-- +----+---------------+------------+-------+-------+-------+----------------------------+ +-- ``` +insert into book values(1,'解忧杂货铺','东野圭吾',27.20,102,98,'upload/books/解忧杂货铺.jpg'), +(2,'边城','沈从文',23.00,102,98,'upload/books/边城.jpg'); +-- 3、创建用户表users,并插入数据 +-- +-- ```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 | | +-- +----------+--------------+------+-----+---------+----------------+ +-- ``` +-- drop table users; +create table users( +id int not null auto_increment, +username varchar(100) not null, +`password` varchar(100) not null, +email varchar(100), +primary key(`id`), +unique key(`username`) +); +-- 尝试添加部分模拟数据,参考示例如下: +-- +-- ```mysql +-- +----+----------+----------------------------------+--------------------+ +-- | id | username | password | email | +-- +----+----------+----------------------------------+--------------------+ +-- | 1 | admin | 112233 | admin@mxdx.com | +-- +----+----------+----------------------------------+--------------------+ +-- ``` +insert into users values(1,'admin','112233','admin@mxdx.com'); +-- 4、创建订单表orders +-- +-- ```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 | | +-- +--------------+--------------+------+-----+---------+-------+ +-- ``` +create table orders( +id varchar(100) not null, +order_time datetime not null, +total_count int not null, +total_amount double(11,2) not null, +state int not null, +user_id int not null, +primary key(`id`) +); +-- 尝试添加部分模拟数据,参考示例如下: +-- +-- ```mysql +-- +----------------+---------------------+-------------+--------------+-------+---------+ +-- | id | order_time | total_count | total_amount | state | user_id | +-- +----------------+---------------------+-------------+--------------+-------+---------+ +-- | 15294258455691 | 2018-06-20 00:30:45 | 2 | 50.20 | 0 | 1 | +-- +----------------+---------------------+-------------+--------------+-------+---------+ +-- ``` +insert into orders values('15294258455691','2018-06-20 00:30:45',2,50.20,0,1); +-- 5、创建订单明细表order_items +-- +-- ```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 | | +-- +----------+--------------+------+-----+---------+----------------+ +-- ``` +create table order_items( +id int not null auto_increment, +count int 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, +primary key(`id`) +); +-- 尝试添加部分模拟数据,参考示例如下: +-- +-- ```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 | +-- +----+-------+--------+------------+----------+-------+------------+----------------+ +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'); +select * from order_items; \ No newline at end of file -- Gitee