Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
frejoh82
Starting Member
3 Posts |
Posted - 2005-10-10 : 02:34:24
|
| I have a DB where all table- and column-names are in my native language. Now I have set up a new DB where the table- and column-names are in English instead. What is the fastest way to copy the data from the original db to the new db? One way is to manually import the data with the import/export-wizard, but then I have to click import, choose source and destination, choose which source column that corresponds to each destination column, and so on, for each of the tables in correct order (due to the relationships among the tables) and then wait for all the data being copied. Is there any better way to do this?Regards Fredrik |
|
|
Kristen
Test
22859 Posts |
Posted - 2005-10-10 : 04:17:36
|
Are all the columns in the same order?If so how aboutINSERT INTO NewDatabase.dbo.MyTableSELECT *FROM OldDatabase.dbo.MyTable You'll need to twiddle IDENTITY_INSERT for those tables where you have an Identity column.The script could be generated by querying the INFORMATION_SCHEMA.TABLES view - something likeSELECT 'INSERT INTO NewDatabase.dbo.' + TABLE_NAME + 'SELECT *FROM OldDatabase.dbo.' + TABLE_NAME+ CHAR(13)+CHAR(10) + 'GO'FROM INFORMATION_SCHEMA.TABLES Kristen |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-10-10 : 04:46:26
|
orTake a backup of OldDBBackup Database OldDB to disk='C:\oldDB.bak'Restore it to the newDBRESTORE DATABASE newDB FROM DISK ='C:\oldDB.bak' WITH MOVE 'oldDB_Data' TO 'C:\Program Files\Microsoft SQL Server\MSSQL\data\newDB_Data.MDF', MOVE 'oldDB_log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL\data\newDB_log.MDF',replace MadhivananFailing to plan is Planning to fail |
 |
|
|
frejoh82
Starting Member
3 Posts |
Posted - 2005-10-10 : 08:23:16
|
| Thank you for your answers. The columns are in the same order, but the tables are not (because of that the names are changed to english names, but I don't know if that has any impact). Madhivanan, does your solution work when the names are different in the two DB:s? (I'm pretty new to SQL Server).The DB:s are located at different servers that I have registered in the Enterprise manager, so I don't know if I can run a sql-query that selects from a DB on one server and inserts in a DB on another server? Once again, thank you for your answers. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-10-10 : 08:52:13
|
| Do you want to keep existing objects in the NewDatabase and only want to copy new objects from old Database to new?MadhivananFailing to plan is Planning to fail |
 |
|
|
frejoh82
Starting Member
3 Posts |
Posted - 2005-10-10 : 09:06:12
|
quote: Originally posted by madhivanan Do you want to keep existing objects in the NewDatabase and only want to copy new objects from old Database to new?MadhivananFailing to plan is Planning to fail
I will run a script that creates the empty "english" tables in the new DB (with "swedish" views that let old applications continue working until I have changed the source code for the applications). So what I want is to copy the data from the old "swedish" DB into my new empty "english" tables in the new DB. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-10-10 : 09:10:17
|
Kris is correct Run this in Query AnalyserSELECT 'INSERT INTO NewDatabase.dbo.' + TABLE_NAME + 'SELECT *FROM OldDatabase.dbo.' + TABLE_NAMEFROM INFORMATION_SCHEMA.TABLESThen copy the results back to Query Analyser and run each insert Statement one by oneMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|