oracle10g-创建表空间 用户
以前一直都是自己拷貝的創(chuàng)建語句來創(chuàng)建oracle的表空間,今天手頭上什么資料都沒有,所以就特意的整理了一下,oracle是如何創(chuàng)建表空間的,所以跟大家分享一下。如果有什么地方寫的不正確,或者是有錯別字,請及時的糾正:
1、為什么要創(chuàng)建表空間?
答:在建立用戶的時候,我們建議數(shù)據(jù)庫管理員要指定用戶的默認表空間。因為我們在利用CREATE語句創(chuàng)建數(shù)據(jù)庫對象,如數(shù)據(jù)庫表的時候,其默認是存儲在數(shù)據(jù)庫的當前默認空間。若不指定用戶默認表空間的話,則用戶每次創(chuàng)建數(shù)據(jù)庫對象的時候,都要指定表空間,顯然,這并不是很合理。
另外要注意,不同的表空間有不同的權限控制。用戶對于表空間A具有完全控制權限,可能對于表空間B就只有查詢權限,甚至連連接的權限的都沒有。所以,合理為用戶配置表空間的訪問權限,也是提高數(shù)據(jù)庫安全性的一個方法。
出自(百度百科)http://baike.baidu.com/view/2973562.htm
2、如何創(chuàng)建表空間?
答:創(chuàng)建示例:
create tablespace "tablecontrols" datafile 'C:\oracle\product\tablecontrols\tablecontrols.dbf' size 300M autoextend on next 100M maxsize unlimited logging online permanent;說明:
create tablespace:創(chuàng)建表空間
tablecontrols:表空間名稱
datafile:默認文件位置
size:表空間大小
autoextend on next 100M:自動擴展表空間100M,當原始空間使用完時
maxsize unlimited:無限制大小
logging online permanent:永久在線記錄
Oracle安裝完后,其中有一個缺省的數(shù)據(jù)庫,除了這個缺省的數(shù)據(jù)庫外,我們還可以創(chuàng)建自己的數(shù)據(jù)庫。對于初學者來說,為了避免麻煩,可以用’Database
Configuration Assistant’向?qū)韯?chuàng)建數(shù)據(jù)庫。創(chuàng)建完數(shù)據(jù)庫后,并不能立即在數(shù)據(jù)庫中建表,必須先創(chuàng)建該數(shù)據(jù)庫的用戶,并且為該用戶指定表空間。
下面是創(chuàng)建數(shù)據(jù)庫用戶的具體過程:
1.假如現(xiàn)在已經(jīng)建好名為’news’的數(shù)據(jù)庫,此時在F:/oracle/product/10.1.0/oradata/目錄下已經(jīng)存在news目錄(注意:我的Oracle10g安裝在F:/oracle下,若
你的Oracle安裝在別的目錄,那么你新建的數(shù)據(jù)庫目錄就在*/product/10.1.0/oradata/目錄下)。
2.在創(chuàng)建用戶之前,先要創(chuàng)建表空間:
其格式為:格式: create 表空間名 datafile ‘數(shù)據(jù)文件名’ size 表空間大小;
如:
SQL> create tablespace news_tablespace datafile ‘F:/oracle/product/10.1.0/oradata/news/news_data.dbf’ size 500M;
其中’news_tablespace’是你自定義的表空間名稱,可以任意取名;'F:/oracle/product/10.1.0/oradata/news/news_data.dbf’是數(shù)據(jù)文件的存放位
置,'news_data.dbf’文件名也是任意取;'size 500M’是指定該數(shù)據(jù)文件的大小,也就是表空間的大小。
3.現(xiàn)在建好了名為’news_tablespace’的表空間,下面就可以創(chuàng)建用戶了:
其格式為:格式: create user 用戶名 identified by 密碼 default tablespace 表空間表;
如:
SQL> create user news identified by news default tablespace news_tablespace;
默認表空間’default tablespace’使用上面創(chuàng)建的表空間。
4.接著授權給新建的用戶:
SQL> grant connect,resource to news; --表示把 connect,resource權限授予news用戶
SQL> grant dba to news; --表示把 dba權限授予給news用戶
授權成功。
1、先查詢空閑空間
select tablespace_name,file_id,block_id,bytes,blocks from dba_free_space;
2、增加Oracle表空間
先查詢數(shù)據(jù)文件名稱、大小和路徑的信息,語句如下:
select tablespace_name,file_id,bytes,file_name from dba_data_files;
3、修改文件大小語句如下
alter database datafile '需要增加的數(shù)據(jù)文件路徑,即上面查詢出來的路徑 'resize 800M;
4、創(chuàng)建Oracle表空間
create tablespace test datafile ‘/home/app/oracle/oradata/oracle8i/test01.dbf’ size 8M autoextend on next 5M maxsize 10M;
create tablespace sales datafile ‘/home/app/oracle/oradata/oracle8i/sales01.dbf’ size 800M autoextend on next 50M maxsize unlimited maxsize //unlimited 是大小不受限制
create tablespace sales datafile ‘/home/app/oracle/oradata/oracle8i/sales01.dbf’ size 800M autoextend on next 50M maxsize 1000M extent management local uniform; //unform表示區(qū)的大小相同,默認為1M
create tablespace sales datafile ‘/home/app/oracle/oradata/oracle8i/sales01.dbf’ size 800M autoextend on next 50M maxsize 1000M extent management local uniform size 500K; //unform size 500K表示區(qū)的大小相同,為500K
create tablespace sales datafile ‘/home/app/oracle/oradata/oracle8i/sales01.dbf’ size 800M autoextend on next 50M maxsize 1000M extent management local autoallocate; //autoallocate表示區(qū)的大小由隨表的大小自動動態(tài)改變,大表使用大區(qū)小表使用小區(qū)
create tablespace sales datafile ‘/home/app/oracle/oradata/oracle8i/sales01.dbf’ size 800M autoextend on next 50M maxsize 1000M temporary; //temporary創(chuàng)建字典管理臨時表空間
create temporary tablespace sales tempfile ‘/home/app/oracle/oradata/oracle8i/sales01.dbf’ size 800M autoextend on next 50M maxsize 1000M
創(chuàng)建本地管理臨時表空間,如果是臨時表空間,所有語句中的datafile都換為tempfile 8i系統(tǒng)默認創(chuàng)建字典管理臨時表空間,要創(chuàng)建本地管理臨時表空間要加temporary tablespace關鍵字 創(chuàng)建本地管理臨時表空間時,不得使用atuoallocate參數(shù),系統(tǒng)默認創(chuàng)建uniform管理方式
為表空間增加數(shù)據(jù)文件:
alter tablespace sales add datafile ‘/home/app/oracle/oradata/oracle8i/sales02.dbf’ size 800M autoextend on next 50M maxsize 1000M;
5、更改自動擴展屬性:
alter database datafile ‘/home/app/oracle/oradata/oracle8i/sales01.dbf’, ‘/home/app/oracle/oradata/oracle8i/sales02.dbf’ '/home/app/oracle/oradata/oracle8i/sales01.dbf autoextend off;
6、刪除表空間:
drop tablespace xxx including contents and datafiles
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎總結
以上是生活随笔為你收集整理的oracle10g-创建表空间 用户的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 成本管控的四要素 是哪四要素
- 下一篇: JSP 活动元素 <jsp:direct