From 61ff40a7cc314e2a4ef173eae42073fc7c8f94cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=BF=97=E9=B9=8F?= <326806914@qq.com> Date: Sun, 19 Feb 2023 21:28:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...55\345\217\245\344\275\234\344\270\232.md" | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 "10 \346\234\261\345\277\227\351\271\217/11\343\200\201DDL\345\222\214DML\350\257\255\345\217\245\344\275\234\344\270\232.md" diff --git "a/10 \346\234\261\345\277\227\351\271\217/11\343\200\201DDL\345\222\214DML\350\257\255\345\217\245\344\275\234\344\270\232.md" "b/10 \346\234\261\345\277\227\351\271\217/11\343\200\201DDL\345\222\214DML\350\257\255\345\217\245\344\275\234\344\270\232.md" new file mode 100644 index 0000000..16aa53c --- /dev/null +++ "b/10 \346\234\261\345\277\227\351\271\217/11\343\200\201DDL\345\222\214DML\350\257\255\345\217\245\344\275\234\344\270\232.md" @@ -0,0 +1,96 @@ +1、创建数据库test01_market + +2、创建表格customers + +use test01_market +create table customers( +c_num int(10), +c_name varchar(50), +c_contact varchar(50), +c_city varchar(50), +c_birth date +); +desc customers; +-- **要求3:**将c_contact字段移动到c_birth字段后面 +ALTER TABLE customers MODIFY c_contact int 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 varchar(70); after c_name; +alter table customers modify c_gender char(1); +-- **要求7:**将表名改为customers_info +ALTER TABLE customers RENAME TO customers_info +-- **要求8:**删除字段c_city +alter table customers_info drop c_city + +2 + +``` + +``` + + create database test02_library; + + create table books( + b_id int(11) not null primary key comment '书编号', + b_name varchar(50) not null comment '书名', + authors varchar(100)not null comment '作者', + price float not null comment '价格', + prbdate year not null comment '出版日期', + note varchar(100) null comment '说明', + num int(11) not null comment '库存' + ); + + insert into books 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','Jane Tim',40,2001,'novel',0), + (4,'Lovey Day','George Byron',20,2005,'novel',30), + (5,'Old land','Old land',30,2010,'law',0), + (6,'The Battle','The Battle',30,1999,'medicine',40), + (7,'Rose Hood','Rose Hood',28,2008,'cartoon',28); + update books set price=+5 where note = 'novel'; + update books set price=40 where b_name='EmmaT'; + delete from books where num=0; + + create database test03_bookstore; + create table book( + id int(11) not null primary key auto_increment, + title varchar(100) not null , + arthor varchar(100) not null , + price double(11,2) not null , + sales int(11) not null , + stock int(11)not null , + img_path varchar(100) not null + ); + insert into book values (1,'解忧杂货店','东野圭吾',27.20,102,98,' upload/books/解忧杂货店.jpg '), + (2,'边城','沈从文',23.00,102,98,'upload/books/边城.jpg '); + create table users( + id int(11)not null primary key auto_increment, + username varchar(100) not null unique , + password varchar(100) not null , + email varchar(100)null + ); + insert into book value (1,'admin',112233,'admin@mxdx.com'); + create table orders( + id varchar(100) not null primary key , + order_time datetime not null , + total_count int(11) not null , + total_amount double(11,2) not null , + state int(11) not null , + user_id int(11) not null unique + ); + insert into book values (15294258455691,'2018-06-20 00:30:45',2,50.20,0,1); + create table order_items( + id int(11) not null primary key auto_increment, + count int(11) not null , + amount double(11,2) not null , + title varchar(100) not null , + author varchar(100) not null , + price double(11,2) not null , + img_path varchar(100) not null , + order_id varchar(100) not null unique + ); + insert into book values (1,1,27.20,'解忧杂货店','东野圭吾',27.20,'static/img/default.jpg',15294258455691), + (2,1,23.00,'边城','沈从文',23.00,'static/img/default.jpg',15294258455691); -- Gitee