oracle中的数据对象有表、视图、索引、序列等

表的相关操作

1.创建表

复制代码
方式一:                                                                     方式二:
create table person( create table person1 id number(18),                                    as name varchar2(5), select * from person age number(3), sex varchar2(4) );
复制代码

 2.删除表

方式一:只会删除表中的内容,不会删除表结构truncate  delete                         方式二:删除表结构
truncate table person drop table person
delete from person where id=123

 3.修改表

alter table
A.追加列
alter table person add (address varchar2(20) default 'shanghai')

B.修改列
alter table person modify (age number(6))
使用modify可以修改数据类型,长度,默认值
请注意:对默认值的修改,只对后面的数据才有效

C.删除列
alter table person drop column age

 

二、视图的相关操作

创建视图                                 删除视图
create view person drop view person
as
select * from emp

视图的优点:1.控制访问,可以把主表中某些不想让别人看见的数据隐藏

                 2.可以将多张表的数据构成一个视图,简化查询

                 3.对视图的修改操作会反映到基表中

 三、序列

创建序列                                            删除序列   drop sequence seq_person

create sequence seq_person
increment by 1
start with 1
nomaxvalue
nocycle
nocache

使用序列实现主键递增

insert into person values(seq_person.nextval,’ll’);

nextval表示下一个值

currval表示当前值

 

posted on 2016-08-13 14:39  rising1234  阅读(1117)  评论(0编辑  收藏  举报