oracle DML语句的学习(1 )

DML语句
(insert,update ,delete,select)

--插入语句
select * from student;
--单独的插入一条语句
insert into student(sno,sname,sex,address,cardid)
values(2,'张三','男','长沙','12313')

update student set sex='女'

rollback;

--插入的时候要注意的地方
(1)要插入的列名的个数必须和值的个数匹配
(2)当有约束的情况下面要考虑约束(check,default,foreign key,unique)
 (3) 数据类型(考虑完整性约束(实体完整性,域完整性,引用完整性,自定义完整性))
(4)在SQL server里面,当有标识列存在的情况下,我们不能显示的给这个标识列插入值
 
--考虑默认约束的情况下面
insert into student(sno,sname,sex,cardid)
values(2,'张三','男','12322')

insert into student
values(3,'李四','女',default,'23')

--一次性插入多行数据
--在SQL SERVER  里面
/*
  --自己输入的值
insert into student
select 110,'张三','男',getdate(),95031 union
select 111,'张2','男',getdate(),95031 union
select 112,'张3','男',getdate(),95031 union
select 113,'张4','男',getdate(),95031

--创建表的同时插入另外一张表里面的数据(表不存在的情况下)
select * into newStudent from student;--同时只能执行一次
select * from newStudent;
truncate table newStudent;
drop table newStudent;

--表已经存在的情况下
insert into newStudent select * from student;

--只复制表结构不要复制数据
select * into newStudent from student where 1=0;

--我们在创建表的同时添加一个字段,在这个字段上面添加标识列
select identity(int,1,1) as sno,sname,ssex into newStudent  from student;
select * from newStudent;
*/
select * from student;
--在oracle里面一次性插入多行记录
insert into student
select 110,'张三','男','长沙','95031' from dual union
select 111,'张2','男','长沙','95032'  from dual union
select 112,'张3','男','长沙','95033'  from dual union
select 113,'张4','男','长沙','95034'  from dual


select * into newStudent from student; --在oracle里面错误

create table newStudent
(
       sno int primary key,
       sname varchar2(20)
)
select * from newStudent;
--往已经存在的表中插入另外一张表中的数据
insert into newStudent select sno,sname from student;

commit;

select * from student;
--更新语句
update 表名 set 字段名=值 where 条件

update student set sname = '王五' where sno =111;

rollback;

--删除语句
delete from student where sno =111;

delete cardid from student;--不能删除指定列的值

--删除表中的所有记录
truncate table student;
--相当于
delete from student;

truncate table tt1;

select * from student;

insert into student
values(1,'张三','男',default,'111')

create table tt
(sno int primary key,
sname varchar2(20))

insert into tt select sno,sname from student;

select * from tt;

truncate table tt;

--查询select
select 12+12 from dual;
--select  执行顺序我们不能随意更改
select
from
where
group by
having
order by

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值