涉及到的知识点有:
KT7_SQL语言——数据操纵——增删改
使用Library数据库:
- 向book表中插入记录(ID:B32DT00001,Name:高等数学,Author:赵丹,publish:同济大学出版社,price:42)
Insert into book values(‘B32DT00001’,‘高等数学’,‘赵丹’,‘同济大学出版社’,42)
- 向book表中插入记录(ID:B32DT00002,Name:离散数学)
Insert into book values(‘B32DT00002’,‘离散数学’,null,null,null)
- 向book表中插入记录(ID:B32DT00003,Name:线性代数,Publish:高等教育出版社)
Insert into book values(‘B32DT00003’,‘线性代数’,null,高等教育出版社,null)
- 向book表中插入记录(ID:B32DT00004,Name:概率论,Publish:NULL,Price:22)
Insert into book values(‘B32DT00004’,‘概率论’,null,null,22)
- 修改book表中ID为B32DT00002的书Author为王旭,publish为高等教育出版社,价格为31)
Update book set author=’ 王旭’,publish=’ 高等教育出版社’,price=31
- 修改book表中publish为NULL的书publish为机械工业出版社
Update book set publish=’ 机械工业出版社’ where publish is null
- 修改book表中价格高于20元的书publish为NULL
Update book set publish=null where price>20
- 删除book表中ID为B32DT00003的书
Delete from book where book_id=’ B32DT00003’
- 删除book表中price为NULL的书
Delete from book where price is null
- 删除book表中高等教育出版社出版的价格高于40元钱的书
Delete from book where publish=’ 高等教育出版社’ and price>40
- 删除王旭借阅记录。
Delete from sc where reader_id in(select reader_id from book where name=’王旭’)
使用students数据库::
- 向student表中插入记录(学号:04101,姓名:张三,性别:男,年龄:20,系别:计算机系)
Insert into student values(‘04101’,‘张三’,‘男’,20,‘计算机系’)
- 向student表中插入记录(学号:04102,姓名:李四)
Insert into student values(‘04102’,‘李四’,null,null,null)
- 向student表中插入记录(学号:04103,姓名:王五,系别:信管系)
Insert into student values(‘04103’,‘王五’,null,null,‘信管系’)
- 向student表中插入记录(学号:04104,姓名:赵六,性别:女,年龄:null,系别:null)
Insert into student values(‘04104’,‘赵六’,‘女’,null,null)
- 修改student表中学号为04103的学生性别为女
Update student set
- 修改student表中学号为04104的学生出生日期为1984-5-1,系别为计算机系
Update student set birthdate=‘1984-5-1’,sdept=‘计算机系’where sno=‘04104’
- 修改出生日期为null的学生出生日期为1984-1-01
Update student set birthdate=‘1984-1-01’ where birthdate is null
- 将计算机系所有学生的出生日期设为null
Update student set birthdate = null where sdept =‘计算机系’
- 删除student表中学号为04104的学生
Delete from student where sno=’ 04104’
- 删除student表中计算机系的所有男生
Delete from student where sex=’男’ and sdept=’ 计算机系’