您的位置:首页 > 数据库 > Oracle

Oracle,视图,序列,索引

2016-05-11 22:21 260 查看

视图:对应于一条select语句。它本身不包含任何数据。它只包含映射到基表的一个查询语句。

分类:简单视图(不包含任何函数,表达式,分组函数),复杂视图(简单视图相反),连接视图(多个表连接)

语法:create view viewName AS Select语句

作用:简化复杂查询,限制数据访问。

对视图操作会影响到基表中的数据。

为了实现视图的安全性:一般再最后加上[with check option]的约束。表示:视图所做的修改必须在 视图所见的范围内。

【read only】约束只读视图。

复杂视图不允许DML操作。

删除视图:drop view viewName

序列:

sequence是一种用来生成唯一数字值的数据库对象。一个序列可以为多个表提供主键值。

创建序列:create sequence sequence_name

                     [start with i] [increment by j]

                     [maxvalue m | nomaxvalue]

                     [minvalue n | nominvalue]

                    [cycle | nocycle][cache p | nocache]

例如:create sequence emp_seq start with 100 increment by 10;

序列中有两个伪列:nextVal       currval

删除序列:drop sequence squence_name;

索引:提高查询效率。

create [unique]index index_name on table(colum[,colum...]);

例如:create index test_index on test(id);

修改索引:alter index index_name rebuild(重建索引)

                   drop index index_name

约束:

包括Not Null,Unique,Primary Key,Foreign Key,Check(检查约束)

例如:Alter table emp add constraint emp_name unique(name);

            Alter table emp add constraint emp_id primary key(id)

外键约束:先建表,在建表后建立外键约束条件。

例如:alter table employees add constraint employees_fk foreign key(deptno) references dept(deptno)

检查约束:

例如:alter table employees add constraint employees_check Check(salary>2000);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: