表数据操作(插入数据、修改数据、删除数据)

p79-p85

#1.【例5.1】向student1表插入一条记录('196001','董明霞','女','1999-05-02','通信’,50)
use stusys;
create table student1 like student;
insert into student1
 values ('196001','董明霞','女','1999-05-02','通信','50');
select * from student1;

 #2.【例5.2】向student1表插入一条记录,学号为“196002”,姓名为“李茜”,专业为“通信”,总学分48,性别为“女”,出生日期为“1998-07-25”
use stusys;
insert into student1 (sno,sname,specially,tc,ssex,birthday)
 values('196002','李茜','通信',48,'女','1998-07-25');
    select * from student1;

 #3.【例5.3】向student1表插入一条记录,学号为“196004”,姓名为“周俊文”,性别为“男”、取默认值,出生日期为“1998-03-10”,专业为空值,总学分为52
use stusys;
 insert into student1(sno,sname,ssex,birthday,specially,tc)
  values('196004','周俊文','男','1998-03-10',null,52);
        select * from student1;

 #4.【例5.4】向student1表插入样本数据,共6条记录
insert ignore into student1
 select * from student;
    
    select * from student1;

 #5.【例5.5】对student1表,重新插入记录('196002','李茜','女','1998-07-25','通信’,48)
use stusys;
replace into student1
 values('196002','李茜','女','1998-07-25','通信','48');

 #6.【例5.6】向student2表插入student表的记录
create table student2 like student;
insert into student2
 select * from student;
    
    select * from student2;

 #7.【例5.7】在student1表中,将学生周俊文的出生日期改为“1999-03-10”
use stusys;
 set sql_safe_updates=0;
    update student1
  set birthday='1999-03-10'
        where sname='周俊文';
select * from student1;

 #8. 【例5.8】在student1表中,将所有学生的学分增加2分
use stusys;
update student1
 set tc=tc+2;
select * from student1;

 #9. 【例5.9】在student1表中,删除学号为196004的行
use stusys;
delete from student1
 where sno='196004';
select * from student1;

 #10.【例5.10】在student1表中,删除所有行 
delete from student1;
select * from student1;

#11.【例5.11】在student2表中,删除所有行
delete from student2;
select * from student2;

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值