views:

221

answers:

3

I have a SQL Server 2008 DB. I want to extract SOME tables (and associated schema, constraints, indexes, etc) and create a SQL Server Express DB. It isn't a sync of the target, we stomp on it.

We ONLY need to do this in the file system (not across the wire). We are not fond of the synchronization stuff and at this point don't know how to run SSIS. We are a C# shop and a little code is ok. Like using the C# bulk import stuff, but that won't create the schema.

Suggestions?

+1  A: 

My suggestion:

  1. Back up the database
  2. Restore under new name and file
  3. Detach restored database from SQL Server

You now have a standalone file that you could use with SQL Server Express.

Scott
Forgive my ignorance, but just to be clear, I can detach a full blown mssql 2008 database and attach to a SQL Server Express?
jeff
I have done this with sql server / express 2005, but I spun up a user instance of the database with sql server express 2005, after I detached it. I didn't try to attach it to sql server express.
Scott
This is what I used and it is good enough for now. There is also SSIS and SMO.
jeff
This procedure will not restore the users and logins (including their passwords). If you need to do this then you will need a script to export the logins in encrypted format and restore them at the other end.
Thomas Bratt
A: 

We use a tool from Red-Gate called SQL Compare to generate schema-complete SQL scripts. It's about $400, but well worth it. You pick the objects you want (users, tables, views, functions - whatever) you want, and it will generate a SQL Script to re-create them in your new database. Essentially, it's the same as Right-Click -> "Script To... New Window" in SSMS, but all at once, and it has a number of other features your shop might find useful as well.

rwmnau
A: 

As Scott pointed out (I couldn't figure out how to comment on his post), you can do a backup and restore, detach and attach from one server version to another assuming that the database is less than 4GB.

Stuart Ainsworth