title: How do you upload SQL Server databases to shared hosting environments?
body: <p>We have a common problem of moving our development SQL 2005 database onto shared web servers at website hosting companies.</p>
  
  <p>Ideally we would like a system that transfers the database structure and data as an exact replica.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>Thus we are left with a messy operation:</p>
  
  <ol>
  <li>Create a script in SQL 2005 that generates the database in SQL 2000 format.</li>
  <li>Run the script to create a SQL 2000 database in SQL 2000.</li>
  <li>Create a script in SQL 2000 that generates the database structure WITHOUT indexes and foreign keys.</li>
  <li>Run this script on the production server. You now have a database structure to upload data to.</li>
  <li>Use SQL 2005 to transfer the data to the production server with Tasks/Import data.</li>
  <li>Use SQL 2000 to generate a script that creates the database with indexes and keys.</li>
  <li>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.</li>
  <li>Run this script on the production database.</li>
  </ol>
  
  <p>Voila! The database is uploaded with all data and keys/constraints in place. What a messy and error prone system.</p>
  
  <p>Is there something better?</p>