4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Oracleでデータインポート時のメモ

Last updated at Posted at 2015-08-13

環境Aのテーブルのデータを環境Bのテーブルにコピーしたい

開発環境と本番環境等、環境とユーザーIDが異なる時のデータ移行時の手順

エクスポート

exp ${TMP_DB_CONNECT} file=dmpファイル名 log=ログファイル名 statistics=none CONSTRAINTS=n GRANTS=n INDEXES=n ROWS=y tables=\(テーブル名\)

インポート

imp ${TMP_DB_CONNECT} file=dmpファイル名 log=ログファイル名 fromuser=\(エクスポートした環境のユーザーID\) touser=\(インポートする環境のユーザーID\) rows=y data_only=y commit=y indexes=n constraints=n grants=n

インポート先に既に同名のテーブルがあるので、インポートするテーブルは別名にしたいとき

dmpファイルのデータをインポート時はテーブルIDを指定出来ないのでテーブルを複数使うしかない。

  1. 既存テーブルを別名のテーブルを作り、そこに退避させておく。
create table 新しいテーブル名1 as select * from 元のテーブル名
  1. 既存テーブルの中身を空にする。※キー重複防止のため
delete from 元のテーブル名
  1. データをインポートする。
  2. インポートしたデータが入っているテーブルを別名でコピー
create table 新しいテーブル名2 as select * from 元のテーブル名
  1. 確保しておいた既存データを正しいテーブルに戻す
delete from 元のテーブル名
insert into 元のテーブル名 select * from 新しいテーブル名1
  1. 退避用テーブルを削除
drop table 新しいテーブル名1 cascade constraint purge;
4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?