insert into press values ('press1','1243323@163.com','fuzhouminhou','13463363763','334543'), ('press2','3467736@qq.com','fuzhougulou','14555697883','334539');
book表
1 2 3 4 5
insert into book values ('23653','book1',3,'press1'), ('34224','book2',0,'press2'), ('23474','book3',13,'press1'), ('33227','book4',1 ,'press1');
borrow_book表
1 2 3 4
insert into borrow_book values ('34224','003837','2022-10-29'), ('33227','449763','2022-10-11','2022-10-28'), ('34224','043858','2022-10-22','2022-11-2');
将student表第4行元组中s_id‘0003837’改成 ‘003837’
1
update student set s_id = ‘003837’where s_id = ‘0003837’
删除第2行元组
1
delete from student where s_id = ‘878433’;
2.数据库查询,视图使用
(1)单表查询
查询所有学生的借书证号和姓名
1
select s_id,s_name from student;
(2)多表连接查询并排序输出
连接student和borrow并查询相关信息按照借书时间降序
1 2 3 4
select student.s_id,s_name,b_id,b_time,r_time from student join borrow_book on student.s_id = borrow_book.s_id order by b_time desc ;
(3)使用聚集函数的查询
查询图书种类数目
1
select count(*) as total from book;
查询最新的借书日期
1
select max(b_time) as latest_date from borrow_book;
(4)分组查询
book表按照出版社名字分组查询每个出版社的图书数目
1
select p_name,count(b_id) from book group by p_name;
(5)嵌套查询
查询最新的借书记录的各项信息
1 2 3
select * from borrow_book where b_time in (select max(b_time) from borrow_book);
(6)创建并使用视图查询。
为student、book、borrow_book三个表创建视图
1 2 3 4
create view borrow_view (s_id,s_name,b_id,b_name,b_time,r_time) as select student.s_id,s_name,book.b_id,b_name,b_time,r_time from borrow_book,student,book where student.s_id=borrow_book.s_id and book.b_id=borrow_book.b_id;