Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import tables without losing indexes and keys in SQL Server 2008

Tags:

sql

sql-server

When I use import/export wizard it loses keys and indexes. I need to import many tables. please help.

Also I created tables by generating script and then do importing, but appear validating error. Maybe I'm doing something wrong?

like image 930
Umed Jan Avatar asked May 17 '12 06:05

Umed Jan


1 Answers

First you make a create script to create tables, keys, indexes. If you right click on database, in the context menu you can click create script on database call the wizard.

With this script you can create your new database. Afterwards you import your data as it is, but your SSIS (aka DTS) wizard don't create the table, but just import the data.

Remark: If you have FOREIGN KEYS, you need to make sure that your SSIS data import part imports in the right order!

I went the way myself to make a big sql textfile which creates all structure where each part is seperated by GO and another file where I create the data (this can be replaced by your wizard).

like image 173
YvesR Avatar answered Sep 19 '22 23:09

YvesR