views:

149

answers:

5

I would like to copy a database (tables, it’s data, stored procs & views) from SQL Server 2008 database to SQL Server Express. Is it possible? If so, would you please let me know how to do it? When I tried, it is giving some error.

Please note that I have only few records in SQL Server 2008 database tables.

Thanks and Regards.. Shruthi Keerthi..

A: 

If copying the entire database, I usually find it easiest to stop the source service, copy the *.mdf file to the appropriate new data directory, and just mount the MDF in the new service. As long as there aren't any changes in the setup (like FILESHARE), then this is the easiest way to clone a database.

And yes, this is possible. I just did this earlier today.

Jarrett Meyer
Note that the SQL Express must be at least at the build number (version and Service Pack number) of the SQL 2008. It is possible to upgrade during attach, but is not possible to downgrade and database versions sometimes change between service pack numbers.
Remus Rusanu
Yeah - we had that problem the first time we tried this. One was 2008SP1, and the other was not SP1. The MDF wouldn't mount. Good call.
Jarrett Meyer
You don't have to stop the service ! Detach the db is enough.
iDevlop
+1  A: 

You can create a backup of the database and them restore that backup into the Express instance.

Another option, since you said you didn't have very many records in the DB, is to generate the SQL statements (right click on the database --> tasks -> generate scripts) and then run that on the Express instance. Then just copy over the tuples you want.

tster
+1  A: 

I prefer to use Backup/Restore when moving a database from one server to another. As long as your SQL Server and SQL Express are the same version, or the one you are moving to is newer than the one you are moving from (SQL 2005 to SQL Express 2008), it should work without a hitch.

C-Pound Guru
A: 

You could also try using the Microsoft Database Publishing Wizard.

It's simple to use and will create a SQL script that you can run to rebuild tables (including data), stored procs, views, etc...

You can download it here:

http://www.microsoft.com/downloads/details.aspx?FamilyID=56E5B1C5-BF17-42E0-A410-371A838E570A&displaylang=en

MoMo
A: 

The quickest way is to "detach" the source database from its server, copy the (2) files to a new name/location and (re)attach each database to the appropriate server. Attach/detach is available as a command or via the SQL Visual Studio.

iDevlop