oracle 表迁移方法 (二) 约束不失效
DB:11.2.0.3.0
在oracle 表迁移方法 (一)中,只是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迁移表至另一个表空间,索引失效,主键约束不失效.
oracle 表迁移方法 (二) 约束不失效的更多相关文章
- oracle 表迁移方法 (一)
在生产系统中,因业务需求,56张表中清空54张表数据,另外两张表数据保留,数据量大约10G左右:1.大部分人想法就是expdp/impdp,的确是这样,哈哈 2.rman 3.以下方法,move 虚拟 ...
- 头像文件上传 方法一:from表单 方法二:ajax
方法一:from表单 html 设置form表单,内包含头像预览div,内包含上传文件input 设置iframe用来调用函数传参路径 <!--表单提交成功后不跳转处理页面,而是将处理数据返回给 ...
- Oracle表、列、约束的操作
获得有关表的信息 可以直接DESCRIBE DESC[RIBE] table_name; 可以通过数据字典 SELECT * FROM user_tables WHERE table_name =xx ...
- Oracle表空间迁移Move Tablespace
move一个表到另外一个表空间时,索引不会跟着一起move,而且会失效.(LOB类型例外) move分为: *普通表move *分区表move *LONG,LOB大字段类型move来进行测试和说明. ...
- Oracle表空间数据文件移动的方法
最近遇到这样的一个问题,Oracle存放表空间文件的盘符 空间不够了,必须把部分表空间迁移出去, [转]http://www.jb51.net/article/77026.htm 实现把用户表空间中的 ...
- Oracle—表、约束、索引、表空间、分区、序列、统计信息
表.约束.索引.表空间.分区.序列.统计信息 一.表及其操作 1.创建表 create table 表名 ( 字段名1 字段类型 默认值 是否为空 , 字段名2 字段类型 默认值 是否为空, 字段名3 ...
- oracle表空间表分区详解及oracle表分区查询使用方法(转+整理)
欢迎和大家交流技术相关问题: 邮箱: jiangxinnju@163.com 博客园地址: http://www.cnblogs.com/jiangxinnju GitHub地址: https://g ...
- Oracle 11gR2 用exp无法导出空表解决方法
Oracle 11gR2 用exp无法导出空表解决方法 在11gR2中有个新特性,当表无数据时,不分配segment以节省空间.Oracle 当然在运行export导出时,空表则无法导出,可是还是有解 ...
- ORACLE 表空间扩展方法
ORACLE 表空间扩展方法 环境: linux系统 工具:PL/SQL DEVELOPER 第一步:查看表空间的名字及文件所在位置: select tablespace_name, file_id, ...
随机推荐
- <路径算法>哈密顿路径变种问题(2016华为软件精英挑战赛初赛)
原创博客,转载请联系博主! 前言:几天前华为的这个软件精英(算法外包)挑战赛初赛刚刚落幕,其实这次是我第二次参加,只不过去年只入围到了64强(32强是复赛线),最后搞到了一个华为的一顶帽子(感谢交大l ...
- 下载编译和测试Android 源代码
http://source.android.com/source/downloading.html 其中出现错误 repo: fatal: error unknown url type: https ...
- opencv学习——兴趣区选取
在OpenCV中,普遍支持ROI和widthStep,函数的操作被限制于感兴趣的区域,要设置或者取消ROI,就要使用cvSetImageROI()和cvResetImage()函数.如过想设置ROI, ...
- .NET MVC4.0与CA对接
1.改web.confog 2.引用CA提供的 dll 3.在controller层加个方法,记得加上授权认证的特性,获取信息 [Authorize] publi void calogin() { H ...
- python其中一个子线程,则退出全部线程,再退出进程
import threading, signal is_exit = False def write_login(self): global is_exit write_log('login rsyn ...
- [vsftp]500 OOPS: cannot change directory
这个报错需要检查 1./etc/passwd 用户的主目录 2./etc/vsftpd/vuser_conf 下每个用户的local_root 3.每个用户目录给ftpuser加上rwx权限,一定要有 ...
- EF,ADO.NET Entity Data Model简要的笔记
1. 新建一个项目,添加一个ADO.NET Entity Data Model的文件,此文件会生成所有的数据对象模型,如果是用vs2012生的话,在.Designer.cs里会出现“// Defaul ...
- No.006 ZigZag Conversion
6. ZigZag Conversion Total Accepted: 98584 Total Submissions: 398018 Difficulty: Easy The string &qu ...
- 华为OJ平台——矩阵乘法
题目描述: 如果A是个x行y列的矩阵,B是个y行z列的矩阵,把A和B相乘,其结果将是另一个x行z列的矩阵C. 输入: 1.第一个矩阵的行数 2.第一个矩阵的列数(也是第二个矩阵的行数) 3.第二个矩阵 ...
- javascript设计模式-组合模式
组合模式所要解决的问题: 可以使用简单的对象组合成复杂的对象,而这个复杂对象有可以组合成更大的对象.可以把简单这些对象定义成类,然后定义一些容器类来存储这些简单对象. 客户端代码必须区别对象简单对象和 ...