数据库三范式

connect用户名/密码 as身份


 disconnect 断掉连接


exit退出


sqlplus,
sqlplusw,


show user


passw 修改密码


alter user用户名 account unlock;账户解锁


实体之间的关系:1对l 一对多 多对多


三范式:


第一范式:不输入重复数据。解决方案是设立主键,主键的作用是标识唯一一条记录,记录不可重复。


一般选择与业务无关的字段,比如自增的id
,选择一个数值类型的字段或者定长字符串
第二范式:避免部分依赖产生的数据冗余。拆表后,通过中间表对应关系。注意:联合主键的概念;

第三范式: 避免传递依赖,通过主外键关系对应解决。


一个表中的外键往往对应另一个表的主键 或者唯一键








查询语句:




表中表名和字段的别名起法
select * from emp t;数据量大的时候不要用
select t.ename [as] 雇员名称 ["雇员 名称"]from emp t
--where =, !=,<>,<,>,<=,>=,any,some,all
first from
sec where
third select
select>=any(select p.sal from emp p);=some >any >=all(相当取最大值)(已用函数替代了)
third select
where e.comm is (not) null选空的数据 ('')
--between and 
select e.* from emp e where e.sal between 2000 and 3000 2000~3000
(where e.sal>=2000 and e.sal<=5000)(这个效率高)
--exists
select * from emp e where exists (select * from emp e where 1=2);
select * from emp e where exists (select 1(e.ename) from emp e where 1=1);
exists(集合)
select *
 from emp e
 where exists(select 1 from emp p where p.empno=e.empno and (p.deptno = 20 or p.deptno = 30));
select * from emp e where e.deptno in (20,30);
[not] exists(数据多) [not]in(数据少)
--like
select * from emp  e where e.ename like '%A%';
select * from emp  e where e.ename like 'D%';
select * from emp  e where e.ename like 'A%';
select * from emp  e where e.ename like '__A_D%';
数据大小写不敏感, 但数据库的值大小写敏感
--escape '\'
select * from emp  e where e.ename like '%%%';(出问题了)
select * from emp  e where e.ename like '%\%%' escape '\';
where 的语句是自下而上的解析方式;
select * from emp e where (e.deptno=10 or e.deptno=30) and e.sal>3000;
select * from emp e where e.sal>2000(7条) and e.deptno=20(5条);
and把检索较少的条件放到后面
or把检索较多的条件放到后面
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值