---
title: "创建表空间"
author: "steadyman"
date: "2010-06-01T14:13:27Z"
tags: []
categories: ["数据库"]
slug: "untitled"
draft: false
lastmod: "2010-06-01T14:19:45Z"
id: 680860
url: "https://steadyman.iteye.com/blog/680860"
---

1.创建临时表空间  
create temporary tablespace website\_temp  
tempfile '/opt/u02/oradata/website/website\_temp01.dbf'  
size 50m autoextend on next 30m maxsize 2048m  
extent management local;

2.创建数据表空间  
create tablespace website\_data  
logging  
datafile '/opt/u02/oradata/website/website\_data01.dbf'  
size 100m autoextend on next 50m maxsize 2048m  
extent management local;

3.创建用户，并指定默认表空间。  
create user website identified by website  
default tablespace website\_data  
temporary tablespace website\_temp;

4.给用户授权。  
grant connect,resource to website;

 

eg:

-- Create the user  
create user DBSHOPUSR  
  identified by ""  
  default tablespace SHOPSPACE  
  temporary tablespace SHOPTMP  
  profile DEFAULT;  
\-- Grant/Revoke role privileges  
grant connect to DBSHOPUSR;  
grant resource to DBSHOPUSR;  
\-- Grant/Revoke system privileges  
grant unlimited tablespace to DBSHOPUSR;

 

===============================================

 

create用户  
　　sql 代码  
　　  
　　 1.Sql代码  
　　SQL&gt; create user visiontv identified by visiontv default tablespace visiontv quota 10m on users;  
　　  
　　 SQL&gt; create user visiontv identified by visiontv default tablespace visiontv quota 10m on users;  
　　  
　　grant privilege  
　　sql 代码  
　　  
　　 1. Sql代码  
　　SQL&gt; grant connect,resource to visiontv;  
　　  
　　SQL&gt; grant connect,resource to visiontv;  
　　  
　　create tablespace  
　　sql 代码  
　　  
　　Sql代码  
　　1. SQL&gt; create tablespace visiontv datafile 'D:\\DBServer\\oracle\\oradata\\oradb01\\vis  
　　2. iontv.ora' size 100m reuse default storage(initial 500k next 500k pctincrease 20  
　　3. );  
　　  
　　 1. SQL&gt; create tablespace visiontv datafile 'D:\\DBServer\\oracle\\oradata\\oradb01\\vis  
　　 2. iontv.ora' size 100m reuse default storage(initial 500k next 500k pctincrease 20  
　　 3. );  
　　  
　　  
　　  
　　import后就可以用了。  
　　  
　　//  
　　  
　　建立用户到用户建表的步骤：  
　　Server  
　　建立：create user 用户名 identified by "密码";  
　　授权：grant create session to 用户名;  
　　 grant create table to 用户名;  
　　 grant create tablespace to 用户名;  
　　 grant create view to 用户名;  
　　  
　　Client：  
　　建立表空间(一般建N个存数据的表空间和一个索引空间)：  
　　create tablespace 表空间名  
　　datafile ' 路径(要先建好路径)\\\*\*\*.dbf ' size \*M  
　　tempfile ' 路径\\\*\*\*.dbf ' size \*M  
　　autoextend on --自动增长  
　　--还有一些定义大小的命令，看需要  
　　default storage(  
　　initial 100K,  
　　next 100k,  
　　);  
　　Server:  
　　授予用户使用表空间的权限：  
　　alter user 用户名 quota unlimited on 表空间;  
　　或 alter user 用户名 quota \*M on 表空间;  
　　自此，才大功告成可以随意建表，运行SQL脚本！  
　　  
　　//1．建表空间  
　　  
　　Sql代码  
　　create tablespace OSDB datafile 'F:\\oracle\\oradata\\glsqjz\\OSDB.ora' size 100m reuse default storage(initial 500k next 500k pctincrease 20);  
　　  
　　create tablespace OSDB datafile 'F:\\oracle\\oradata\\glsqjz\\OSDB.ora' size 100m reuse default storage(initial 500k next 500k pctincrease 20);  
　　2．建用户  
　　  
　　Sql代码  
　　create user OSUSER identified by OSUSER  
　　  
　　create user OSUSER identified by OSUSER;//identified by 后面的是密码，前面的是用户名  
　　  
　　3．用户授权  
　　  
　　Sql代码  
　　grant resource,connect,RECOVERY\_CATALOG\_OWNER to OSUSER ;  
　　  
　　grant create table to OSUSER ;  
　　  
　　alter user OSUSER quota unlimited ON OSDB;  
　　  
　　alter user OSUSER default tablespace OSDB;  
　　  
　　grant resource,connect,RECOVERY\_CATALOG\_OWNER to OSUSER ;  
　　  
　　grant create table to OSUSER ;  
　　  
　　alter user OSUSER quota unlimited ON OSDB;  
　　  
　　alter user OSUSER default tablespace OSDB;  
　　4．删除表空间  
　　  
　　Sql代码  
　　DROP TABLESPACE TableSpaceName INCLUDING CONTENTS AND DATAFILES;  
　　  
　　DROP TABLESPACE TableSpaceName INCLUDING CONTENTS AND DATAFILES;  
　　5．删除用户  
　　  
　　Sql代码  
　　DROP USER User\_Name CASCADE  
　　  
　　DROP USER User\_Name CASCADE  
　　  
　　6．删除表的注意事项  
　　  
　　在删除一个表中的全部数据时，须使用Sql代码  
　　TRUNCATE TABLE 表名  
　　  
　　TRUNCATE TABLE 表名;因为用DROP TABLE，DELETE * FROM 表名时，TABLESPACE表空间该表的占用空间并未释放，反复几次DROP，DELETE操作后，该TABLESPACE上百兆的空间就被耗光了。