深度优先

这个家伙好懒,除了文章什么都没留下

0%

【Oracle】同义词序列视图索引

数据库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
--创建表空间
create tablespace stu
datafile 'd:\stu.dbf'
size 5m
autoextend on

--创建用户名
create user stu
identified by stu

grant connect to stu

grant resource to stu

create table stuInfo --学生信息
(
stuID number primary key,
stuName varchar2(10),
stuSex char(2)
);
insert into stuInfo values(1,'Eric','男');
insert into stuInfo values(2,'Mike','男');
insert into stuInfo values(3,'Lily','女');
insert into stuInfo values(4,'Lucy','女');
create table subInfo --课程信息
(
subID number primary key,
subName varchar2(20)
);
insert into subInfo values(1,'C语言');
insert into subInfo values(2,'SQL基础');
insert into subInfo values(3,'JAVA');

create table markInfo --成绩信息
(
stuID int references stuInfo(stuID),
subID int references subInfo(subID),
score number(3),
primary key (stuID,subID)
);
insert into markInfo values(1,1,98);
insert into markInfo values(1,2,90);
insert into markInfo values(1,3,80);
insert into markInfo values(2,1,50);
insert into markInfo values(2,2,40);
insert into markInfo values(2,3,60);
insert into markInfo values(3,1,70);
insert into markInfo values(3,2,95);

select * from stuinfo
select * from subInfo
select * from markInfo

同义词

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
--1、什么同义词 
--别名

--2、作用
--简化对象的名字
select * from myemp

--3、创建语法
create public synonym myemp for scott.emp

--4、删除语法
drop public synonym myemp

select * from stuinfo
select stuid as 编号,stuname 姓名 from stuinfo

序列

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
--1、什么是序列?
--标识列,自动增长
--sql server:identity(1,1)
--oracle:sequence

--2、作用,等同于identity,为编号字段,提供自增长

--3、语法
select * from stuinfo

create sequence myseq
increment by 1 --步长
start with 1001 --初始值
maxvalue 100-- 无上限
minvalue 1
cycle

create table stuInfo1 --学生信息
(
stuID number primary key,
stuName varchar2(10),
stuSex char(2)
);

insert into stuinfo1 values(myseq.nextval,'葬爱K','男')
insert into stuinfo1 values(myseq.nextval,'葬爱Q','女')
insert into stuinfo1 values(myseq.nextval,'葬爱A','男')
insert into stuinfo1 values(myseq.nextval,'葬爱B','女')

insert into stuinfo values(myseq.nextval,'葬爱Q','女')

select * from stuinfo1

--4.删除序列
drop sequence myseq

--5、查询序列值
select myseq.currval from dual

视图

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
--1、什么是视图?
--虚拟表

--2、作用
--1)简化,复杂的表查询
--2)保密,视图名字不能推断表名
--3) 缓冲,合作开发

--创建视图之前要先授权
grant dba to stu
revoke dba from stu

--创建视图
create view empinfo
as
select * from stuinfo666

--查询视图
select * from empinfo
--drop view empinfo

索引

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
--1、什么是索引?
--提高查询效率

select * from stuinfo where stuname = 'eric'
stuid --聚集索引(主键)
stuname --非聚集(where条件中的字段)
stusex --非聚集

--2、索引分类
--普通索引
create index Instuid on stuinfo(stusex)

--组合索引
create index innamesex on stuinfo(stuname,stusex)

--唯一索引
create unique index inid on stuinfo(stuname)