2009年9月14日星期一

捣鼓Oracle

--创建数据库,貌似创建数据库的sql较复杂,
创建数据库的脚本:
-----------------------------------------------------------
CREATE DATABASE dbtest
LOGFILE
GROUP 1 ('/opt/oracle/oradata/dbtest/redo01.log','/opt/oracle/oradata/dbtest/redo01_1.log') size 100m reuse,
GROUP 2 ('/opt/oracle/oradata/dbtest/redo02.log','/opt/oracle/oradata/dbtest/redo02_1.log') size 100m reuse,
GROUP 3 ('/opt/oracle/oradata/dbtest/redo03.log','/opt/oracle/oradata/dbtest/redo03_1.log') size 100m reuse
MAXLOGFILES 50
MAXLOGMEMBERS 5
MAXLOGHISTORY 200
MAXDATAFILES 500
MAXINSTANCES 5
ARCHIVELOG
CHARACTER SET UTF8
NATIONAL CHARACTER SET UTF8
DATAFILE '/opt/oracle/oradata/dbtest/system01.dbf' SIZE 1000M EXTENT MANAGEMENT LOCAL
SYSAUX DATAFILE '/opt/oracle/oradata/dbtest/sysaux01.dbf' SIZE 1000M
UNDO TABLESPACE UNDOTS DATAFILE '/opt/oracle/oradata/dbtest/undo.dbf' SIZE 500M
DEFAULT TEMPORARY TABLESPACE TEMP TEMPFILE '/opt/oracle/oradata/dbtest/temp.dbf' SIZE 500M
;

--还是用Database Configuration Assistant 来创建和配置数据库。
--创建表空间
create tablespace official_tablespace
datafile 'E:\oracle\product\10.2.0\oradata\spring\official_data.dbf'
size 5M
autoextend on;--自动增长


--建完表空间 建用户
create user official3 identified by offi1234 default tablespace official_tablespace;

--接着授权给新建的用户

grant connect,resource to official3; --表示把 connect,resource权限授予news用户
grant dba to official3; --表示把 dba权限授予给news用户

--表的数据备份:PL/SQL----->TOOLS--------->Export Tables
------------------------------------------------
删除表空间
DROP TABLESPACE TableSpaceName INCLUDING CONTENTS AND DATAFILES;
删除用户
DROP USER official CASCADE
删除表的注意事项
在删除一个表中的全部数据时,须使用
TRUNCATE TABLE 表名
因为用DROP TABLE,DELETE * FROM 表名时,TABLESPACE表空间该表的占用空间并未释放,
反复几次DROP,DELETE操作后,该TABLESPACE上百兆的空间就被耗光了。

参考:http://www.cnblogs.com/smartvessel/archive/2009/07/06/1517690.html
http://ilinux.javaeye.com/blog/178306

没有评论:

发表评论