日期:2014-05-16  浏览次数:20381 次

oracle知识
    Oracle默认用户  SYS   SYSTEM   SCOTT  

1-数据库中所有数据字典表和视图都存储在 SYS 模式中。SYS用户主要用来维护系统信息和管理实例。
2-SYSTEM 是默认的系统管理员,该用户拥有Oracle管理工具使用的内部表和视图。通常通过SYSTEM用户管理    数据库用户、权限和存储等
3-SCOTT用户是Oracle 数据库的一个示范帐户,在数据库安装时创建


4-超级用户权限:执行数据库实例的管理工作,使用企业管理器时只能使用这两个身份
SYSDBA:系统管理员,具有数据库服务器的最高权限
SYSOPER:系统操作员,具有打开、关闭、备份、恢复等权限
SYS:超级用户,执行数据库的管理任务,具有数据库的最高权限
连接示例:
conn sys/tiger as sysdba;
conn sys/tiger as sysoper;
conn / as sysdba;

5-创建表空间
create tablespace accpspace
datafile 'd:\oracle\oradata\ora92\accp.dbf'
[size 10m] [autoextend [off|on]] [next 1m];

--创建临时表空间
   create temporary tablespace tab_temp tempfile 'e:/aa.dbf'
size 10M [autoextend [off|on]] [next 1m]

6-.删除表空间
  drop tablespace tbs;
  彻底删除、包括物理删除(临时表空间同样)
  drop tablespace tbs including contents and datafiles;

truncate table t1; //删除表内所有数据 

7.创建用户
  create user accp  --用户名
  identified by accp  --密码
  default tablespace tbs1  -- 默认表空间,不指定默system表空间
  temporary tablespace temp;  --指定临时表空间

   alter user accp default tablespace tas; --指定表空间
   alter user accp temporary tablespace tase; --指定临时表空间

   create sequence student_id; --创建序列(标识列)
      插入数据时引用  student_id.nextVal   从1开始
8.授权
  grant connect to accp; --授予登陆权限
  grant resource to accp;  --授予资源使用权
  grant connect,resource to accp;--也行
  grant create session to test; --登录权限
  grant create table to test; --建表能力
  grant unlimited tablespace to test; --无限制表空间
9.回收权限
  revoke create session from test;
10.跨用户授权
  grant select on emp to accp; --授予accp select emp表的权限
  grant all on emp to accp;  --所有权限
11.切换登陆用户
  conn accp/accp;
12.修改密码
  alter user accp identified by aptech; --修改为aptech
13.查看当期用户
  show user;
  select user from dual;
14.删除用户
  drop user accp;  --删除空用户
  drop user accp cascade;--删除用户下所有的数据对象
15.跨用户授权
  grant select on emp to accp; --授予accp select emp表的权限
  grant update on emp to test;
  grant all on emp to accp;  --所有权限
14.
   select * from tab; --查看用户下所有的表

15.
   查看当前数据库名: select name from v$database; 或 show parameter db;

16.
   查看数据库实例:show parameter instance; 或 select instance_name from v$instance

17.
   数据库域名在存在于参数文件中,他的参数是db_domain.
   查询数据库域名 方法一:select value from v$parameter where name = 'db_domain';
方法二:show parameter domain

18.
   查询数据文件 select name from v$datafile;
   查询控制文件 select name from v$controlfile;
   查询日志文件 select member from v$logfile;

19.
   //创建标准索引
     create index 索引名 ON 表名(字段名);
   //删除索引
     drop index 索引名;
   //增加列
        Alter table t1 add b varchar2(20); 
   //修改数据类型、长度
Alter table t1 modify b number(2);  
   //删除列
  Alter table t1 dorp column b;

   //设置主键
Alter table t1 add constraint pk_t1 primary key (id);
   //设置唯一约束
Alter table t1 add constraint uq_t1 unique(b);
   //设置检查约束
Alter table t1 add constraint ck_t1 check(b>18);
   //设置默认值约束
Alter table t1 modify city default ('BeiJing');
    //设置外键约束
Alter table t1 add cons