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把检索较多的条件放到后面
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把检索较多的条件放到后面