1. Modify book information
1. Create a book table
Information stored in the book table (book number, book name, book category, book price) Note : Before creating the table, remember to delete the table habitually, in case there is a table before, and an error is reported!
drop table if exists books;
create table books( id int ,
name varchar ( 20 ) ,
type varchar ( 20 ) ,
price decimal ( 5 , 2 )
) ;
2. Add data
insert into books values ( 1 , 'Java核心技术' , '计算机类' , 50.0 ) ,
( 2 , 'Mysql原理' , '计算机类' , 45.5 ) ,
( 2 , '高等数学' , '必修类' , 20.5 ) ,
( 3 , '计算机基础' , '计算机类' , 30.0 ) ;
3. Query the data in the table
select * from books;
4. Modify operations
Modify the book information of "Java Core Technology" and modify the price to 61
update books set price = 61 where name like 'Java核心技术' ;
select * from books;
5. Delete operation
delete from books where type = '计算机类' ;
select * from books;
2. Commodity table operation
Product table storage information (product number, product price, product inventory quantity)
1. Create a table
drop table if exists goods;
create table goods( id int ,
price decimal ( 5 , 2 ) ,
number int
) ;
2. Increase the data in the table
insert into goods values ( 1 , 30.00 , 100 ) ,
( 2 , 35.5 , 200 ) ,
( 3 , 150 , 50 ) ;
select * from goods;
3. Alias display data
select id 编号, price 价格, number 库存 from goods;
4. Modify the records of all commodities with inventory greater than 30, and increase the price by 50 yuan
update goods set price = price+ 50 where number > 30 ;
select * from goods;
5. Delete records in the commodity table where the price is greater than 50 and less than 100
delete from goods where price > 50 and price < 100 ;
select id 编号, price 价格, number 库存 from goods;