开发者

Copying data from one oracle database to another oracle database using C#

开发者 https://www.devze.com 2023-02-12 22:37 出处:网络
What is the standard way of copying data from one oracle database to another. 1) Read data from source table and copy to temp table on开发者_开发知识库 destination using configuration( i.e. there are

What is the standard way of copying data from one oracle database to another.

1) Read data from source table and copy to temp table on开发者_开发知识库 destination using configuration( i.e. there are more than 1 table and each table has separate temp table) 2) Right now there is no clob data, but in future clob data might be used. 3) Read everything to memory(if large data read in chunks)

Should not use Oracle links Should not use files Code should be only using C# but not any database procedures.


One way that I've used to do this is to use a DataReader on the source database and just perform inserts on the target database (using Bind Parameters for sure).

Note that the DataReader is excellent at not using much memory as it moves through a table (I believe that by default it uses a Fast Forward, Read Only cursor). This means that only a small amount of data is held in memory at a given time.

Here are the things to watch out for:

Relationships

If you're working with data that has relationships, you're going to need to deal with that. There are two ways that I've seen to deal with this:

  1. Temporarily drop the relationships in the target database before doing the copy, then recreate them after.
  2. Copy the data in the correct order for the relationships to work correctly (this is usually pretty difficult / inefficient)

Auto Generated Id Values

These columns are usually handled by disabling the auto increment functionality for the given table and allowing identity insert (I'm using some SQL Server terms, I can't remember how it works on Oracle).

Transactions

If you're moving a lot of data, transactions will be expensive.

Repeatability / Deleting Target Data

Unless you're way more awesome than the rest of us, you'll probably have to run this thing more than once (at least during development). That means you might want a way to delete the target data.

Platform Specific Methods

In SQL Server, there are ways to perform bulk inserts that are blazingly fast (by giving up little things like referential integrity checking). There might be a similar feature within the Oracle toolset.

Table / Column Metadata

I haven't had to do this in Oracle yet, but it looks like you can get metadata on tables and columns using the views mentioned here.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号