--insert 向表中插入数据
--基本语法 insert into 表名 (字段名) values (对应的字段值)
--向指定的字段写入值,其它的字段为空,字段的顺序无关,只要字段值对应
insert into student (s_id,s_name) values(8,'小李');
--省略形式 insert into 表名 values (对应的字段值)和数据表中的顺序对应,不能省略
insert into student values(9,'小张',19,'女','一年一班');
--通过查询结果导入数据,查询结果字段类型必须和表一致
insert into stu
select s_id,s_name from student;
--练习,给student subject teacher score各插入5条数据
--数据更新语句
--基本语法 update 表名 set [字段名=新值]列表 批量更新,不加过滤的话,会更新所有的行
update stu set s_name='大王';
update stu set s_name='大王' where s_name='小李';
update stu set s_name='大华',s_id=16 where s_name='小华';
select * from student;
--删除数据
--delete from 表名 where 过滤条件
--如果不加过滤条件,会删除整张表的数据,类似于DDL中trunc
--跟trunc的区别是,DDL自动提交事务,不能返回,DML不会自动提交,可以回滚
delete from student;
delete from stu where s_id=7;
insert into student values(11,'小刘',19,default,'一年一班');
insert into student (s_id,s_name) values(12,'小钱');
--数据合并操作
--有条件的选择插入或者更新操作,达到两张数据表内容统一
merge into stu
using stu2
on (stu2.s_id=stu.s_id)
when matched then
update set stu.s_name=stu2.s_name
when not matched then
insert values(stu2.s_id,stu2.s_name);
DML数据操纵举例
最新推荐文章于 2022-10-24 23:28:09 发布