Sql数据库--更新语句

阅读 421

2022-01-04

涉及到的知识点有:

KT7_SQL语言——数据操纵——增删改

使用Library数据库:

  1. book表中插入记录(IDB32DT00001Name:高等数学,Author:赵丹,publish:同济大学出版社,price42

Insert  into  book  values(‘B32DT00001’,‘高等数学’,‘赵丹’,‘同济大学出版社’,42

  1. book表中插入记录(IDB32DT00002Name:离散数学)

Insert  into  book  values(‘B32DT00002’,‘离散数学’,nullnullnull

  1. book表中插入记录(IDB32DT00003Name:线性代数,Publish:高等教育出版社)

Insert  into  book  values(‘B32DT00003’,‘线性代数’,null,高等教育出版社,null

  1. book表中插入记录(IDB32DT00004Name:概率论,PublishNULLPrice22

Insert  into  book  values(‘B32DT00004’,‘概率论’,nullnull22

  1. 修改book表中IDB32DT00002的书Author为王旭,publish为高等教育出版社,价格为31

Update book set author=’ 王旭’,publish=’ 高等教育出版社’,price=31

  1. 修改book表中publishNULL的书publish为机械工业出版社

Update book set publish=’ 机械工业出版社’  where publish is null

  1. 修改book表中价格高于20元的书publishNULL

Update book set  publish=null where price>20

  1. 删除book表中IDB32DT00003的书

Delete from book where book_id=’ B32DT00003’

  1. 删除book表中priceNULL的书

Delete from book where price is null

  1. 删除book表中高等教育出版社出版的价格高于40元钱的书

Delete from book where publish=’ 高等教育出版社’ and price>40

  1. 删除王旭借阅记录。

Delete from sc where reader_id in(select reader_id from book where name=’王旭’)

使用students数据库::

  1. student表中插入记录(学号:04101,姓名:张三,性别:男,年龄:20,系别:计算机系)

Insert  into  student values(‘04101’,‘张三’,‘男’,20,‘计算机系’)

  1. student表中插入记录(学号:04102,姓名:李四)

Insert  into  student values(‘04102’,‘李四’,nullnullnull

  1. student表中插入记录(学号:04103,姓名:王五,系别:信管系)

Insert  into  student values(‘04103’,‘王五’,nullnull,‘信管系’)  

  1. student表中插入记录(学号:04104,姓名:赵六,性别:女,年龄:null,系别:null

Insert  into  student values(‘04104’,‘赵六’,‘女’,nullnull

  1. 修改student表中学号为04103的学生性别为女

Update student  set

  1. 修改student表中学号为04104的学生出生日期为1984-5-1,系别为计算机系

Update student  set  birthdate=1984-5-1’,sdept=‘计算机系’where sno=04104

  1. 修改出生日期为null的学生出生日期为1984101

Update student  set birthdate=1984101 where birthdate is null

  1. 将计算机系所有学生的出生日期设为null

Update student  set birthdate = null where sdept =‘计算机系’

  1. 删除student表中学号为04104的学生

Delete  from student where sno=’ 04104’

  1. 删除student表中计算机系的所有男生

Delete  from student where sex=’’ and sdept=’ 计算机系

精彩评论(0)

0 0 举报