首页 > 代码库 > ORACLE 建库过程总结

ORACLE 建库过程总结

1,忘记sys密码

  打开CMD命令窗口,执行以下操作:

1,SQLPLUS /NOLOG;
2,
3,CONNECT / AS SYSDBA
4,
5,ALTER USER SYS IDENTIFIED BY 新密码
6,
7,ALTER USER SYSTEM IDENTIFIED BY 新密码
8,

2,以sys账号登陆

   建立用户表空间,索引表空间,创建用户,授权,分配配额:

--创建用户表空间--基础区
CREATE TABLESPACE TABLESPACE_NAME DATAFILE
  d:/oracledata/TABLESPACE_NAME01.dbf SIZE 100M AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED;
--创建索引表空间--基础区
CREATE TABLESPACE TPPAML_BSE_IDX DATAFILE
  d:/oracledata/TABLESPACE_NAME_IDX01.dbf SIZE 100M AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED;

--创建用户
CREATE USER USERNAME
   IDENTIFIED BY "USER_PASSWORD"
  DEFAULT TABLESPACE TPPAML_BSE;

-- 给用户TPPAML授权 
GRANT CONNECT TO USERNAME; 
GRANT RESOURCE TO USERNAME;
GRANT CREATE TABLE TO USERNAME;  --建表权限
GRANT CREATE ALL TABLE TO USERNAME; --在所有表空间下建表权限(考虑是否需要)

--1 System Privilege for username
GRANT UNLIMITED TABLESPACE TO USERNAME; 

-- 1 Tablespace Quota for username 无限制的空间限额
ALTER USER TPPAML QUOTA UNLIMITED ON TPPAML_BSE;

3,用新建的账号登陆建表即可

CREATE TABLE TABLE_NAME
(
   ID             VARCHAR2(32) NOT NULL,
   NAME           VARCHAR2(32)
)
TABLESPACE TABLESPACE_NAME
   PCTFREE 10
   INITRANS  1
   MAXTRANS  255
   STORAGE
   (
      INITIAL   1M
      NEXT      1M
      MINEXTENTS  1
MAXEXTENTS UNLIMITED PCTINCREASE
0 ); ALTER TABLE TABLE_NAME ADD CONSTRAINT PRIMART_TABLE PRIMARY KEY (ID) --外键 USING INDEX TABLESPACE TABLESPACE_NAME PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE ( INITIAL 1M NEXT 1M MINEXTENTS 1
MAXEXTENTS UNLIMITED PCTINCREASE
0 );