[20160910]快速修改表的schema.txt

简介: [20160910]快速修改表的schema.txt --以前也做过例子: http://blog.itpub.net/267265/viewspace-741154/ http://blog.itpub.net/267265/viewspace-744787/ --第1种就是修改数据字典的情况,但是这种存在一定的风险,我当时的测试版本11.2.0.1还有修改obj$的字段spare3. --第2种就是利用交换分区的方法。
[20160910]快速修改表的schema.txt

--以前也做过例子:
http://blog.itpub.net/267265/viewspace-741154/
http://blog.itpub.net/267265/viewspace-744787/

--第1种就是修改数据字典的情况,但是这种存在一定的风险,我当时的测试版本11.2.0.1还有修改obj$的字段spare3.
--第2种就是利用交换分区的方法。这种方式小量很行,大量也是不合适。

--第1种合适大量修改,但是确实存在一定风险,至少要严格测,除了以上方法,其实还可以传输表空间模式。
--还是通过例子来说明问题.

1.环境:
SCOTT@test01p> @ ver1
PORT_STRING                    VERSION        BANNER                                                                               CON_ID
------------------------------ -------------- -------------------------------------------------------------------------------- ----------
IBMPC/WIN_NT64-9.1.0           12.1.0.1.0     Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production              0

CREATE TABLESPACE LFREE DATAFILE
  'D:\APP\ORACLE\ORADATA\TEST\TEST01P\LFREE01.DBF' SIZE 100M AUTOEXTEND ON NEXT 1280K MAXSIZE UNLIMITED
LOGGING
ONLINE
EXTENT MANAGEMENT LOCAL AUTOALLOCATE
BLOCKSIZE 8K
SEGMENT SPACE MANAGEMENT AUTO
FLASHBACK ON;

SCOTT@test01p> create table t tablespace lfree as select * from  dba_objects;
Table created.

SCOTT@test01p> select count(*) from t;
  COUNT(*)
----------
     91698

grant dba to test identified by test;

2.传输表空间:
--以sys用户登录:
SYS@test01p> execute dbms_tts.transport_set_check('lfree');
PL/SQL procedure successfully completed.

SYS@test01p> select * from transport_set_violations;
no rows selected

SYS@test01p> alter tablespace lfree read only;
Tablespace altered.

--奇怪windows 要使用双引号。
D:\tmp\expdp>exp userid=\"/@test01p as sysdba\" transport_tablespace=y tablespaces=lfree file=lfree.exp
exp userid=\"/@test01p as sysdba\" transport_tablespace=y tablespaces=lfree file=lfree.exp
Export: Release 12.1.0.1.0 - Production on Sat Sep 10 21:43:42 2016
Copyright (c) 1982, 2013, Oracle and/or its affiliates.  All rights reserved.
Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set
Note: table data (rows) will not be exported
About to export transportable tablespace metadata...
For tablespace LFREE ...
. exporting cluster definitions
. exporting table definitions
. . exporting table                              T
. exporting referential integrity constraints
. exporting triggers
. end transportable tablespace metadata export
Export terminated successfully without warnings.

--备份表空间。可以使用os命令来拷贝,因为现在是read only。12c drop表空间支持keep datafiles。
SYS@test01p> drop tablespace lfree including contents keep datafiles;
Tablespace dropped.

D:\tmp\expdp>imp userid=\"/@test01p as sysdba\" transport_tablespace=y tablespaces=lfree datafiles=D:\APP\ORACLE\ORADATA\TEST\TEST01P\LFREE01.DBF fromuser=scott touser=test file=lfree.exp
imp userid=\"/@test01p as sysdba\" transport_tablespace=y tablespaces=lfree datafiles=D:\APP\ORACLE\ORADATA\TEST\TEST01P\LFREE01.DBF fromuser=scott touser=test file=lfree.exp
Import: Release 12.1.0.1.0 - Production on Sat Sep 10 21:52:04 2016
Copyright (c) 1982, 2013, Oracle and/or its affiliates.  All rights reserved.
Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

Export file created by EXPORT:V12.01.00 via conventional path
About to import transportable tablespace(s) metadata...
import done in ZHS16GBK character set and AL16UTF16 NCHAR character set
. importing SCOTT's objects into TEST
. . importing table                            "T"
Import terminated successfully without warnings.


--以test用户登录,检查:
TEST@test01p> select count(*) from scott.t;
select count(*) from scott.t
                           *
ERROR at line 1:
ORA-00942: table or view does not exist


TEST@test01p> select count(*) from test.t;
  COUNT(*)
----------
     91698

--可以发现现在表t已经变成了test schema。

SYS@test01p> alter tablespace lfree read write ;
Tablespace altered.

--这种方式存在风险就是注意drop tablespace时注意要保留数据文件,不要删除数据文件!!
目录
相关文章
|
SQL 测试技术 索引
[20120816]快速修改表的schema.txt
[20120816]快速修改表的schema.txt    前几天在测试环境,开发人员把几个表建成system schema,需要修改成别的schema模式.当然方法很多,ctas,exp/imp等等.
627 0
|
SQL 索引
[20120922]快速修改表的schema.txt
[20120922]快速修改表的schema.txt 如果想快速交换表的schema,常规方法是exp/imp,expdp/impdp或者ctas,在线重定义表等等,如果表很小,方法还可以.
710 0
|
关系型数据库 Oracle 索引
[20120418]CREATE SCHEMA.txt
[20120418]CREATE SCHEMA.txtCREATE SCHEMA Purpose     Use the CREATE SCHEMA statement to create multiple tables and views and perform.
813 0
|
SQL Shell 测试技术
[20161023]为什么以前可以这样的表.txt
[20161023]为什么以前可以这样的表.txt --上午看https://oracleblog.org/working-case/ora-01401-impdp-same-character/ CREATE TABLE ASS_ACC...
800 0
[20131211]对比两个表的不同信息.txt
[20131211]对比两个表的不同信息.txt昨天看了http://jonathanlewis.wordpress.com/2013/12/09/differences/博客,通过包dbms_rectifier_diff可以查看两个表存在那些不同。
784 0
[20150115]insert多个表.txt
[20150115]insert多个表.txt --别人给我提出一个问题,要把表拆开2个表,能否快速完成这个工作。还是通过例子来说明: SCOTT@test> @ver1 PORT_STRING                    VERSION  ...
715 0
|
Oracle 关系型数据库
[20171113]修改表结构删除列相关问题3.txt
[20171113]修改表结构删除列相关问题3.txt --//维护表结构删除字段一般都是先 ALTER TABLE SET UNUSED (); --//然后等空闲时候删除列.
784 0
|
SQL 监控 测试技术
[20171113]修改表结构删除列相关问题4.txt
[20171113]修改表结构删除列相关问题4.txt --//连续写了3篇修改表结构删除列的相关问题,链接如下: http://blog.itpub.net/267265/viewspace-2147158/ http://blog.
998 0
|
Oracle 关系型数据库 数据库管理
[20171113]修改表结构删除列相关问题2.txt
[20171113]修改表结构删除列相关问题2.txt --//测试看看修改表结构删除列产生的redo向量,对这些操作细节不了解,分析redo看看. 1.环境: SCOTT@book> @ &r/ver1 PORT_STRING             ...
1044 0
|
SQL Oracle 关系型数据库
[20171113]修改表结构删除列相关问题.txt
[20171113]修改表结构删除列相关问题.txt --//维护表结构删除字段一般都是先 ALTER TABLE SET UNUSED (); --//然后等空闲时候删除列.
867 0

热门文章

最新文章