Copy Sql Server 2008 Databse schema only to Another Sql server 2008 Database on same machine -


i have sql server 2008 database

is there way create new database , copy schema of existing database objects newly created database using sql query or stored procedure

first you'll need make full backup of database want copy:

backup database database1  disk = 'x:\fullpath\advworksdata.bak'    format; 

where x:\fullpath full path location can backup on disk.

next you'll need create new database (if haven't already):

create database database2; 

and you'll need restore on top of database:

restore filelistonly     database1;  restore database database2    database1    move 'database1_data' 'x:\fullpath\database2.mdf',    move 'database1_log' 'x:\fullpath\database2.ldf'; go 

where x:\fullpath full path you're second databases files exist.

some caveats

  1. move 'database1_data' , 'database1_log' default logical file names. can differ. can find logical names under properties of database.
  2. 'x:\fullpath\database2.mdf' , 'x:\fullpath\database2.ldf' may not both exist in same location and can differ default locations. can find locations under properties of database.

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -