Oracle_建立、增加、刪除表空間相關指令碼
--建立表空間和資料檔案,單個檔案10000m,以1024m自動擴充套件,儲存路徑,先建立好檔案,檔案文需要大寫 create tablespace TABLESPACE_NAME logging datafile 'J:\ORCL_PROJ\TABLESPACE_NAME_1.dbf'size 5000m --儲存地址 初始大小5000m autoextend on next 1024m MAXSIZE UNLIMITED, --每次擴充套件1024M,無限制擴充套件 'J:\ORCL_PROJ\TABLESPACE_NAME_2.dbf'size 5000m autoextend on next 1024m MAXSIZE UNLIMITED, 'J:\ORCL_PROJ\TABLESPACE_NAME_3.dbf'size 5000m autoextend on next 1024m MAXSIZE UNLIMITED, 'J:\ORCL_PROJ\TABLESPACE_NAME_4.dbf'size 5000m autoextend onnext 1024m MAXSIZE UNLIMITED, 'J:\ORCL_PROJ\TABLESPACE_NAME_5.dbf'size 5000m autoextend onnext 1024m MAXSIZE UNLIMITED extent management local;
--建立使用者,關聯表空間 CREATE USER username IDENTIFIED BY userpassword DEFAULT TABLESPACE "TABLESPACE_NAME" TEMPORARY TABLESPACE "TEMP" PROFILE DEFAULT ACCOUNT UNLOCK;
--新增使用者許可權 GRANT "CONNECT" TO username; GRANT "RESOURCE" TO username; GRANT "DBA" TO username;
--給表空間增加資料檔案 alter tablespace TABLESPACE_NAME(表空間名) add datafile 'j:\orcl_proj\TABLESPACE_NAME_3.dbf' size 5000m autoextend on next 1024m maxsize unlimited;
--刪除表空間和對應資料檔案 drop tablespace TABLESPACE_NAME including contents and datafiles;
--強制刪除使用者 drop user username cascade;
--刪除關聯索引 select segment_name,partition_name,tablespace_name from dba_extents where tablespace_name=upper('TABLESPACE_NAME')
--生成語句 select 'alter table '||owner||'.'||table_name||' drop constraint '||constraint_name||' ;' from dba_constraints where constraint_type in ('U', 'P') and (index_owner, index_name) in (select owner, segment_name from dba_segments where tablespace_name = 'TABLESPACE_NAME');