oracle 表遷移方法 (二) 約束不失效
DB:11.2.0.3.0
在中,只是move了一張普通的表,如果表的欄位帶有主鍵約束呢 ?
[oracle@db01 ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.3.0 Production on Mon Nov 3 18:40:16 2014
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/orcl/system01.dbf
/u01/app/oracle/oradata/orcl/sysaux01.dbf
/u01/app/oracle/oradata/orcl/undotbs01.dbf
/u01/app/oracle/oradata/orcl/users01.dbf
建立dahao表空間
SQL> create tablespace dahao datafile '/u01/app/oracle/oradata/orcl/dahao01.dbf' size 100m;
Tablespace created.
建立yoon使用者
SQL> create user yoon identified by yoon default tablespace dahao;
User created.
授權
SQL> grant dba to yoon;
Grant succeeded.
當前使用者
SQL> show user
USER is "YOON"
建立測試表yoon
SQL> create table yoon as select * from scott.emp;
Table created.
檢視當前表索引
SQL> select index_name from user_indexes;
no rows selected
建立empno主鍵約束
SQL> alter table yoon add constraint pk_empno primary key (empno);
Table altered.
SQL> conn / as sysdba
Connected.
SQL> select name from v$datafile;
NAME
------------------------------------------------------------------------------------------------------------------------
/u01/app/oracle/oradata/orcl/system01.dbf
/u01/app/oracle/oradata/orcl/sysaux01.dbf
/u01/app/oracle/oradata/orcl/undotbs01.dbf
/u01/app/oracle/oradata/orcl/users01.dbf
/u01/app/oracle/oradata/orcl/dahao01.dbf
建立yoon表空間
SQL> create tablespace yoon datafile '/u01/app/oracle/oradata/orcl/yoon01.dbf' size 100m;
Tablespace created.
SQL> conn yoon/yoon;
Connected.
建立索引
SQL> create index idx_deptno on yoon(deptno);
Index created.
設定yoon表為只讀
SQL> alter table yoon.yoon read only;
Table altered.
遷移yoon表
SQL> alter table yoon.yoon move tablespace yoon;
Table altered.
修改使用者預設表空間
SQL> alter user yoon default tablespace yoon;
User altered.
檢視使用者對應預設表空間
SQL> select username,default_tablespace from dba_users;
USERNAME DEFAULT_TABLESPACE
------------------------------ ------------------------------
SYS SYSTEM
SYSTEM SYSTEM
SCOTT USERS
GGS USERS
YOON YOON
檢視索引狀態
SQL> select INDEX_NAME,TABLE_OWNER,TABLE_NAME,STATUS from user_indexes where index_name='PK_EMPNO' ;
INDEX_NAME TABLE_OWNER TABLE_NAME STATUS
------------------------------ ------------------------------ ------------------------------ --------
PK_EMPNO YOON YOON UNUSABLE
SQL> select INDEX_NAME,TABLE_OWNER,TABLE_NAME,STATUS from user_indexes where index_name='IDX_DEPTNO' ;
INDEX_NAME TABLE_OWNER TABLE_NAME STATUS
------------------------------ ------------------------------ ------------------------------ --------
IDX_DEPTNO YOON YOON UNUSABLE
重建索引
SQL> alter index IDX_DEPTNO rebuild ;
Index altered.
SQL> select INDEX_NAME,TABLE_OWNER,TABLE_NAME,STATUS from user_indexes where index_name='PK_EMPNO' ;
INDEX_NAME TABLE_OWNER TABLE_NAME STATUS
------------------------------ ------------------------------ ------------------------------ --------
PK_EMPNO YOON YOON UNUSABLE
SQL> select INDEX_NAME,TABLE_OWNER,TABLE_NAME,STATUS from user_indexes where index_name='IDX_DEPTNO' ;
INDEX_NAME TABLE_OWNER TABLE_NAME STATUS
------------------------------ ------------------------------ ------------------------------ --------
IDX_DEPTNO YOON YOON VALID
設定yoon表為讀寫
SQL> alter table yoon read write;
Table altered.
插入資料
SQL> insert into yoon (empno) values (7934);
insert into yoon (empno) values (7934)
*
ERROR at line 1:
ORA-01502: index 'YOON.PK_EMPNO' or partition of such index is in unusable state
重建索引
SQL> alter index PK_EMPNO rebuild;
Index altered.
SQL> insert into yoon (empno) values (7934);
insert into yoon (empno) values (7934)
*
ERROR at line 1:
ORA-00001: unique constraint (YOON.PK_EMPNO) violated
經上述測試發現,透過move遷移表至另一個表空間,索引失效,主鍵約束不失效.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28939273/viewspace-1319859/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 修改表名索引約束觸發器等物件不會失效索引觸發器物件
- oracle 表遷移方法 (一)Oracle
- 資料遷移判斷非空約束
- Oracle約束Oracle
- oracle 約束Oracle
- 遷移後處理外來鍵約束的問題
- Oracle分割槽表遷移Oracle
- ORACLE表批量遷移表空間Oracle
- JavaScript------表單約束驗證DOM方法JavaScript
- Oracle定義約束 外來鍵約束Oracle
- 查詢oracle表的資訊(表,欄位,約束,索引)Oracle索引
- Oracle 9i升級19C 遷移關於失效索引的梳理方法Oracle索引
- ORACLE 跨平臺遷移方法Oracle
- Oracle10g新特性——利用RMAN遷移表空間(二)Oracle
- 連載二:Oracle遷移文章大全Oracle
- (轉)oracle資料庫中所有外來鍵約束失效SQL語句Oracle資料庫SQL
- 【STATS】Oracle遷移表統計資訊Oracle
- oracle中的約束Oracle
- oracle 約束詳解Oracle
- Oracle約束簡介Oracle
- oracle鍵約束控制Oracle
- MySQL·捉蟲動態·唯一鍵約束失效MySql
- 遷移資料到Oracle的方法思考Oracle
- 如何在ORACLE中修改表的約束條件啊Oracle
- Oracle中表空間、表、索引的遷移Oracle索引
- yugong之多張表oracle到mysql遷移GoOracleMySql
- 【SQL】15 SQL 約束(Constraints)、NOT NULL 約束、UNIQUE 約束、PRIMARY KEY 約束、FOREIGN KEY 約束、CHECK 約束、DEFAULT約束SQLAINull
- oracle 註釋和約束Oracle
- 新增/刪除約束(Oracle)Oracle
- oracle的延遲約束Oracle
- oracle 表空間下資料檔案遷移的三種方法Oracle
- Oracle 表空間資料檔案遷移Oracle
- Oracle 帶LOB欄位的表的遷移Oracle
- yugong之單張表oracle到mysql遷移GoOracleMySql
- Oracle 不同平臺間表空間遷移Oracle
- 利用PLSQL實現表空間的遷移(二)SQL
- Oracle 11g系列:約束Oracle
- 修改oracle的約束欄位Oracle