数据库对象的同义词和序列

回顾简单的数据库权限等命令;

解锁用户和锁定用户
alter user scott account lock/unlock;
//system下查看系统中的用户
select * dba_users;

//创建用户名和密码
create user wj identified by wj;
identified by 
//授予连接权和建表权
grant connect to wj;连接权
grant resource to wj;建表
//授予查询和更新权限
grant select to wj;
grant Update to wj;
//授予增删改查权限
grant all to wj;
//移除所有权限
grant revoke to wj;
//授予wj用户操作scott用户下emp表的权限
grant all on scott.emp to wj;
//移除wj用户操作scott用户下emp表的权限
grant all on scott,emp from wj;
//授予wj用户操作scott用户下emp表的权限
grant connect on scott.emp to wj;
grant select on scott.emp to wj;
grant Resource on scott.emp to wj;
grant Update on scott.emp to wj;

//移除wj用户操作scott用户下emp表的权限
grant connect on scott.emp from wj;
grant select on scott.emp to wj;
grant Resource on scott.emp from wj;
grant Update on scott.empfrom wj;

grant<--_>revoke
  to <---->from

同义词:私有的,公共的(public)

    同义词是现有对象的一个别名

   私有同义词只能在其模式内访问,且不能与当前模式的对象同名

私有同义词的定义:---定义私有同义词

system下创建

create synonym e for scott.emp;  

删除同义词

drop synonym e;

 公有同义词可被所有的数据库用户访问

定义公共的同义词;

create public synonym e for scott.emp;

 删除前面创建的同义词dd

create or replace public synonym dd for scott.emp

序列:--序列是用于生成唯一、连续序号;可以是升序的,也可以是降序的

NEXTVAL 返回序列的下一个值
CURRVAL 返回序列的当前值

--创建序列
   create sequence toys_seq
   start with 10
   increment by 2
   maxvalue 20
   minvalue 1
   nocycle
   cache

   --查询用户当前的序列
   select * from user_sequences;

 删除序列;

DROP SEQUENCE  toys_seq;

sys.dual的用法

            select toys_seq.nextval from dual; --获得序列toys_seq的下一个值
            select toys_seq.currval from dual; --获得序列toys_seq的当前值

猜你喜欢

转载自baihe747.iteye.com/blog/2142760