Petras Petras - 2 years ago 82
SQL Question

How do you upload SQL Server databases to shared hosting environments?

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:

  1. Create a script in SQL 2005 that generates the database in SQL 2000 format.

  2. Run the script to create a SQL 2000 database in SQL 2000.

  3. Create a script in SQL 2000 that generates the database structure WITHOUT indexes and foreign keys.

  4. Run this script on the production server. You now have a database structure to upload data to.

  5. Use SQL 2005 to transfer the data to the production server with Tasks/Import data.

  6. Use SQL 2000 to generate a script that creates the database with indexes and keys.

  7. 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.

  8. 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?

Answer Source

Scott Gu had written few posts on this topic :

SQL Server Database Publishing Toolkit for Web Hosting

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download