CTOCIO IT专家网

天极传媒 比特网 | 天极网 | IT专家网 | IT商网 | 52PK游戏网 | 手机天极 | IT分众 |
IT专家网搜索

数据库 | Oracle | DB2 | SQL Server | MySQL | 商业智能 | BI | DBA | Sybase| SQL Server 2008

您现在的位置: IT专家网 > 数据库子站 > 数据库技巧

如何把数据导入不同的表空间

作者: ,  出处:论坛, 责任编辑: 李书琴, 
2007-11-15 00:00
  本文教你如何把数据导入不同的表空间……

  问:我在进行数据迁移时,本来希望把数据导入到不同于原系统的表空间,在导入之后意外的发现数据却被导入了原表空间。请问应给怎么解决这个问题?

  答:我来举一个简单的例子:

  首先如果缺省的用户具有DBA权限,那么导入时会按照原来的位置导入数据,即导入到原表空间。

  $ imp bjbbs/passwd file=bj_bbs.dmp fromuser=jive touser=bjbbs grants=n
  Import: Release 8.1.7.4.0 - Production on Mon Sep 22 11:49:41 2003
  (c) Copyright 2000 Oracle Corporation. All rights reserved.
  Connected to: Oracle8i Enterprise Edition Release 8.1.7.4.0 - 64bit Production
  With the Partitioning option
  JServer Release 8.1.7.4.0 - 64bit Production
  Export file created by EXPORT:V08.01.07 via conventional path
  Warning: the objects were exported by JIVE, not by you
  import done in ZHS16GBK character set and ZHS16GBK NCHAR character set
  . . importing table "HS_ALBUMINBOX" 12 rows imported
  . . importing table "HS_ALBUM_INFO" 47 rows imported
  . . importing table "HS_CATALOG" 13 rows imported
  . . importing table "HS_CATALOGAUTHORITY" 5 rows imported
  . . importing table "HS_CATEGORYAUTHORITY" 0 rows imported
  ....
  . . importing table "JIVEUSERPROP" 4 rows imported
  . . importing table "JIVEWATCH" 0 rows imported
  . . importing table "PLAN_TABLE" 0 rows imported
  . . importing table "TMZOLDUSER" 3 rows imported
  . . importing table "TMZOLDUSER2" 3 rows imported
  About to enable constraints...
  Import terminated successfully without warnings.

  查询发现仍然导入了USER表空间

  $ sqlplus bjbbs/passwd
  SQL*Plus: Release 8.1.7.0.0 - Production on Mon Sep 22 11:50:03 2003
  (c) Copyright 2000 Oracle Corporation. All rights reserved.
  Connected to:
  Oracle8i Enterprise Edition Release 8.1.7.4.0 - 64bit Production
  With the Partitioning option
  JServer Release 8.1.7.4.0 - 64bit Production
  SQL> select table_name,tablespace_name from user_tables;
  TABLE_NAME TABLESPACE_NAME
  ------------------------------ ------------------------------
  HS_ALBUMINBOX USERS
  HS_ALBUM_INFO USERS
  HS_CATALOG USERS
  HS_CATALOGAUTHORITY USERS
  HS_CATEGORYAUTHORITY USERS
  HS_CATEGORYINFO USERS
  HS_DLF_DOWNLOG USERS
  ...
  JIVEWATCH USERS
  PLAN_TABLE USERS
  TMZOLDUSER USERS
  TABLE_NAME TABLESPACE_NAME
  ------------------------------ ------------------------------
  TMZOLDUSER2 USERS
  45 rows selected.

  2.回收用户unlimited tablespace权限即可以导入到用户缺省表空间

  SQL> create user bjbbs identified by passwd
  2 default tablespace bjbbs
  3 temporary tablespace temp
  4 /
  User created.
  SQL> grant connect,resource to bjbbs;
  Grant succeeded.
  SQL> grant dba to bjbbs;
  Grant succeeded.
  SQL> revoke unlimited tablespace from bjbbs;
  Revoke succeeded.
  SQL> alter user bjbbs quota 0 on users;
  User altered.
  SQL> alter user bjbbs quota unlimited on bjbbs;
  User altered.
  SQL> exit
  Disconnected from Oracle8i Enterprise Edition Release 8.1.7.4.0 - 64bit Production
  With the Partitioning option
  JServer Release 8.1.7.4.0 - 64bit Production

  最后重新导入数据

  $ imp bjbbs/passwd file=bj_bbs.dmp fromuser=jive touser=bjbbs grants=n
  Import: Release 8.1.7.4.0 - Production on Mon Sep 22 12:00:51 2003
  (c) Copyright 2000 Oracle Corporation. All rights reserved.
  Connected to: Oracle8i Enterprise Edition Release 8.1.7.4.0 - 64bit Production
  With the Partitioning option
  JServer Release 8.1.7.4.0 - 64bit Production
  Export file created by EXPORT:V08.01.07 via conventional path
  Warning: the objects were exported by JIVE, not by you
  import done in ZHS16GBK character set and ZHS16GBK NCHAR character set
  . . importing table "HS_ALBUMINBOX" 12 rows imported
  . . importing table "HS_ALBUM_INFO" 47 rows imported
  . . importing table "HS_CATALOG" 13 rows imported
  . . importing table "HS_CATALOGAUTHORITY" 5 rows imported
  . . importing table "HS_CATEGORYAUTHORITY" 0 rows imported
  . . importing table "HS_CATEGORYINFO" 9 rows imported
  . . importing table "HS_DLF_DOWNLOG" 0 rows imported
  ....
  . . importing table "JIVEUSER" 102 rows imported
  . . importing table "JIVEUSERPERM" 81 rows imported
  . . importing table "JIVEUSERPROP" 4 rows imported
  . . importing table "JIVEWATCH" 0 rows imported
  . . importing table "PLAN_TABLE" 0 rows imported
  . . importing table "TMZOLDUSER" 3 rows imported
  . . importing table "TMZOLDUSER2" 3 rows imported
  About to enable constraints...
  Import terminated successfully without warnings.
  SQL> select table_name,tablespace_name from user_tables;
  TABLE_NAME TABLESPACE_NAME
  ------------------------------ ------------------------------
  HS_ALBUMINBOX BJBBS
  HS_ALBUM_INFO BJBBS
  HS_CATALOG BJBBS
  HS_CATALOGAUTHORITY BJBBS
  ....
  JIVETHREAD BJBBS
  JIVETHREADPROP BJBBS
  JIVEUSER BJBBS
  JIVEUSERPERM BJBBS
  JIVEUSERPROP BJBBS
  JIVEWATCH BJBBS
  PLAN_TABLE BJBBS
  TMZOLDUSER BJBBS
  TABLE_NAME TABLESPACE_NAME
  ------------------------------ ------------------------------
  TMZOLDUSER2 BJBBS
  45 rows selected.

  至此数据即被导入到正确的用户表空间中了。

网友评论

笔名 
请您注意:遵守国家有关法律、法规,尊重网上道德,承担一切因您的行为而直接或间接引起的法律责任。    IT专家网友拥有管理笔名和留言的一切权利。
  • 周排行榜
  • 月排行榜

邮件订阅


    
天极服务 | 关于我们 | 网站律师 | 加入我们 | 联系我们 | 广告业务 | 友情链接 | 我要挑错
All Rights Reserved, Copyright 2004-2008, Ctocio.com.cn
渝ICP证B2-20030003号 如有意见请与我们联系 powered by 天极内容管理平台CMS4i