views:

259

answers:

5

What is the best way to develop on SQL Server 2005 machine locally while you get your database design and application design smoothed out and then deploy to a shared host?

In the MySQL / phpMyAdmin world you have an option to export the table as the DDL Statement with the data represented as a bunch of inserts following the DDL. Using this you can drop a table, recreate it, and load it with data all from a query window.

Is there anything close to this in the Microsoft world? Is there any free/open source tools to help with this migration of data?

+1  A: 

Generate Scripts of all your database schema (tables, stored procedures, views, etc.) and also do exports of your data (if necessary) and then run those scripts and import the data into your shared host. Depending on that host, you could get access through Management Studio and it would be an even easier process.

TheTXI
What format should you export the data too? I'm working with 15 to 20 tables.
tyndall
Simplest form would be some form of CSV (comma separated values) list, either in a text file or in excel spreadsheet. However you export it, you can re-import it. They wouldn't give you the option if they didn't also support taking it back in.
TheTXI
A: 

TheTXI's solution is good. Making a backup and restoring it also works, and is sometimes (depending on the ISP/host's lockdown of MS SQL) the only option.

Steven A. Lowe
+2  A: 

SQL Server Management Studio Express (which is free) includes the "Generate Scripts" option that TheTXI referred to.

The Database Publication Wizard is a more lightweight product (also free) that is specifically for generating export scripts for both schema and data.

Caveat — neither is 100% reliable. I've sometimes had to tinker with the scripts to get them to run, particularly regarding the order of dependent objects. It's a pain, but still better than starting from scratch.

As RedBeard mentioned, you should be keeping track of your DDL scripts, in particular the "diff" scripts that will upgrade you from one revision of the database to the next. In that case, these tools would not be useful during the normal development cycle. However, if you haven't been managing your scripts this way, these tools can help you get started, and are also good for creating new instances, migrating instances, comparing snapshots, and a host of other things.

harpo
I've used the Database Publication Wizard successfully on locked down hosts (GoDaddy).
Gromer
Yes, that's the situation that brought me to it as well. Also, because you can't remote into these databases, I had to develop my own web-based interface for running large script batches, such as are generated by these utilities.
harpo
Funny. I asked a Microsoft employee (SQL Server consultant) about a tool like this in 2005 or 2006. Looks like there was finally enough demand for this. Wonder if they will ever build the DPW into the SQL Server product. This is exactly what I was looking for.
tyndall
+1  A: 

A couple of options:

Keep track of your database's DDL scripts

You have a set of scripts that can be executed to create or update your database. You could actually pull DDL statements from your SQL Server database itself. Look in the INFORMATION_SCHEMA system views.

Example, to get information about stored procedures and their definitions, look at the ROUTINE_DEFINITION field (keep in mind you'll find some other procedures that you didn't define, but come built-in to sql server):

SELECT SPECIFIC_SCHEMA,SPECIFIC_CATALOG, SPECIFIC_NAME, ROUTINE_DEFINITION 
FROM INFORMATION_SCHEMA.ROUTINES

Use Visual Studio Database Team Edition (Comes with Developer Team Edition)

Basically it does the above for you and streamlines the setup and revision control of your database. It allows you to define data and structure, has a lot of Unit testing features as well.

Backup and Restore of your local database

Backup your local database, upload it to your host, restore the database there.

Copy/Move your MDF/LDF files

Similar to the backup/restore, you need to detach your database, copy or move the files to your web host and then reattach there.

Use the SQL Server engine to attach MDF/LDF files in the App_Data folder of ASP.NET

There should be a few examples of how this is done. It treats the database as a file, but it does require a SQL Server engine to be installed on the web host.

As an example, taken from an ASP.NET MVC template (web.config):

<connectionStrings>
  <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
</connectionStrings>
Redbeard 0x0A
Not sure the Backup and Restore / Copy/Move stuff works on many webhosts. Are you saying the "data dude" edition of VS2008 has some ability to move data around? not just the DDL?
tyndall
"Data Dude" has a lot of features that can be used in developing and deploying databases. It supports Data Generation, Schema Comparisons/Syncs, Test fixtures. Plus you define your database structures using the easy to understand CREATE TABLE syntaxes/scripts. The Schema compare functionality will generate all the alter scripts required to move from one version of a schema to another version. I was personally blown away when I saw the demos. It is also easy to put it into source control. MS did a great job with this tool.
Redbeard 0x0A
+1 should take some more time to learn this "diffing" database stuff. I know I will get slammed for this... but: Most times I develop locally until the product is 98% complete. Then I go live and make changes from there. Now I only do this on my personal hobby projects. At my real job everything is internal on a network and all my sites are intranet-based.
tyndall
A: 

You can also choose a shared hosting company that provides a tool like myLittleBackup (www.mylittlebackup.com) so that you can easily install/restore your db on the shared server.

Can a tool like that work against a local database behind a ridiculously locked-down firewall?
tyndall
myLittleBackup is installed and provided by the webhosting company, which means that there is no firewall prob. Once installed and configured, customers only have to upload a backup of their db using myLittleBackup interface and click a restore button. myLittleBackup then automatically does all the tricky things like user mapping, size limit checking, etc...