We have a common problem of moving our development SQL 2005 database onto shared web servers at website hosting companies.
Ideally we would like a system that transfers the database structure and data as an exact replica.
This would be commonly achieved by restoring a backup. But because they are shared SQL servers, we cannot restore backups – we are not given access to the actual machine.
We could generate a script to create the database structure, but then we could not do a data transfer through the menu item Tasks/Import Data because we might violate foreign key constraints as tables are imported in an order the conflicts with the database schema. Also, indexes might not be replicated if they are set to auto generate.
Thus we are left with a messy operation:
- Create a script in SQL 2005 that generates the database in SQL 2000 format.
- Run the script to create a SQL 2000 database in SQL 2000.
- Create a script in SQL 2000 that generates the database structure WITHOUT indexes and foreign keys.
- Run this script on the production server. You now have a database structure to upload data to.
- Use SQL 2005 to transfer the data to the production server with Tasks/Import data.
- Use SQL 2000 to generate a script that creates the database with indexes and keys.
- Copy the commands that generate the indexes and foreign keys only. These are located after the table creation commands. Note: In SQL 2005, the indexes and foreign keys are generated as one and cannot be easily separated.
- Run this script on the production database.
Voila! The database is uploaded with all data and keys/constraints in place. What a messy and error prone system.
Is there something better?