开发者

best way to transfer data from one database to other in ms sql express 05 using c#

I have old sql express 05 database where some tables contains important data that is want to transfer to new sql express 05 database.

I want to preserve auto ids of old data in tables, but dont want to transfer all tables only some tables i want to transfer开发者_高级运维, but problem is I have to achieve this using c# 3.5 winform app

My tasks are:

  1. create new blank database
  2. transfer some old tables to new database
  3. create other tables in new database

Anybody have good approch to acchive it using c#,stored procedurs etc.


use winform to launch an SSIS package programmatically.

http://msdn.microsoft.com/en-us/library/ms136090.aspx

you'll have to buy (or msdn download perhaps?) sql developer edition to get integration services (SSIS)


Check if SQL express accepts this command: set identity sales on, or similar; this will allow you to insert the data from the old table(s) to the new table and keeping your existing identity values in the new tables.

I would use a store procedure to do the data transfer work. You can call/execute the procedure from your C# winform app.

Before inserting the data, set the identity option on for each table you want to transfer data.

The command to transfer data for each table can be something like:

Set identity newtable on

insert into newtable (identitycolum, column1, column2, column3)

Select identitycolum, column1, column2, column3 From oldtable

Set identity newtable off

Hope that helps.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜