一.修改图书信息
1.创建图书表
- 图书表存储的信息(图书编号,图书名字,图书类别,图书价格)
注:创建表之前,切记习惯性的进行一下删除表操作,以防之前已经存在表,报错!
drop table if exists books;
create table books(id int,
name varchar(20),
type varchar(20),
price decimal(5,2)
);
2.添加数据
insert into books values(1,'Java核心技术','计算机类',50.0),
(2,'Mysql原理','计算机类',45.5),
(2,'高等数学','必修类',20.5),
(3,'计算机基础','计算机类',30.0);
3.查询表中数据
select * from books;
4. 修改操作
- 修改“Java核心技术”的图书信息,将价格修改为61
update books set price = 61 where name like 'Java核心技术';
select * from books;
5.删除操作
delete from books where type = '计算机类';
select * from books;
二.商品表操作
- 商品表存储信息(商品编号,商品价格,商品库存数量)
1.创建表
drop table if exists goods;
create table goods(id int,
price decimal(5,2),
number int
);
2.增加表中数据
insert into goods values(1,30.00,100),
(2,35.5,200),
(3,150,50);
select * from goods;
3.别名显示数据
select id 编号,price 价格, number 库存 from goods;
4.修改所有库存大于30的商品记录,将价格增加50块
update goods set price = price+50 where number > 30;
select * from goods;
5.删除商品表中,价格大于50并且是小于100的记录
delete from goods where price > 50 and price < 100;
select id 编号,price 价格, number 库存 from goods;