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

oracle基本操作,自己亲手做过了
--创建表空间(其中TWC.DBF不需要我们手工创建)
-----创建了一个大小为20M的表空间,自动增长以5M的大小,可以无限制增加下去,
------只要你的磁盘够大
create tablespace tian datafile 
 'D:\Oracle1\TWC.DBF' size 20M autoextend on next 5M maxsize unlimited 
 logging online permanent extent management local autoallocate 
 blocksize 8K 
 segment space management manual 
 flashback on;


--修改表空间
alter tablespace tian1 add datafile 'F:\oraData\tablesecond04\tablesecond_DATA2.DBF' size 10000M;


alter database datafile 'F:\oraData\tablesecond04\tablesecond_DATA2.DBF' autoextend on next 100m maxsize unlimited;
---创建用户(其中表空间为 tian)
create user twc identified by twc
  default tablespace tian 
   temporary tablespace temp
   profile default 
    account unlock;
--创建用户的语句的说明
create user  用户名
identified by  密码(不要加引号)
default tablespace 默认表空间名 quota 5M on 默认表空间名
[temporary tablespace 临时表空间名]
[profile 配置文件名]                                          //配置文件
[default role 角色名]                                        //默认角色
[password expire]                                             //密码失效
[account lock]                                                   //账号锁定
修改用户
alter user 用户名 identified by 密码 quota 10M on 表空间名
alter user 用户名 account lock/unlock
删除用户
drop user 用户名 [cascade].如果要删除的用户中有模式对象,必须使用cascade.




--用户的角色及其授权
 -- Roles for tablesecond
 grant DBA TO twc with admin option;
 grant aq_administrator_role to twc with admin option;
 grant mgmt_user to twc;
 alter user twc default role all;
--建另外一个用户
CREATE USER twc1
  IDENTIFIED BY twc1
  DEFAULT TABLESPACE tian
  TEMPORARY TABLESPACE TEMP
  PROFILE DEFAULT
  ACCOUNT UNLOCK;
--角色和授权
  --  Roles for tablesecond
  GRANT DBA TO twc1 WITH ADMIN OPTION;
  GRANT AQ_ADMINISTRATOR_ROLE TO twc1 WITH ADMIN OPTION;
  GRANT MGMT_USER TO twc1;
  ALTER USER twc1 DEFAULT ROLE ALL;
  -- 1 System Privilege for tablesecond
  GRANT UNLIMITED TABLESPACE TO twc1 WITH ADMIN OPTION;
  -- 1 Tablespace Quota for tablesecond 
  ALTER USER twc1 QUOTA UNLIMITED ON tian;


-- 创建表
create table users1(
userid int primary key ,
username varchar2(30) NOT NULL,
pwd  varchar2(30) NOT NULL 
);
--如果创建上面的表,那么系统将为你生成,以下此表的具体的代码:
-- Create table
create table USERS1
(
  USERID   INTEGER not null,
  USERNAME VARCHAR2(30) not null,
  PWD      VARCHAR2(30) not null
)
tablespace TIAN
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );
-- Create/Recreate primary, unique and foreign key constraints 
alter table USERS1
  add primary key (USERID)
  using index 
  tablespace TIAN
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );
create sequence userid;--创建序列
--另外一种创建序列的方式
--创建一个从1开始,默认最大Í