Oracle,视图,序列,索引

视图:对应于一条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);


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值