Home All Groups Group Topic Archive Search About

Creating a new database using an existing as template

Author
31 Aug 2006 2:47 PM
Johan Sjöström
What are the "best practices" for this? I'm using SQL Server 2000.

I basically want an identical database, but with a new name and new
datafiles.

Right now, I have copied the template db's mdf/ldf files to new ones,
and issued the following statements:

sp_attach_db @dbname = 'newdb',
@filename1='c:\Program\Microsoft SQL Server\MSSQL\Data\newdb.mdf',
@filename2='c:\Program\Microsoft SQL Server\MSSQL\Data\newdb_log.ldf'

But when I look at the newdb properties in EM, "Data Files" tab,
although the locations are correct, the "File Name" is still the
template db's. Doesn't seem safe to ignore that.

I have tried a 2nd approach also: Restoring a backup of the template db
into a new db, but then I got errors saying "logical file is not part
of database".

Cheers,
Johan Sjöström
MSc, MCAD

Author
31 Aug 2006 2:54 PM
Aaron Bertrand [SQL Server MVP]
>>
But when I look at the newdb properties in EM, "Data Files" tab,
although the locations are correct, the "File Name" is still the
template db's. Doesn't seem safe to ignore that.
>>

Do you mean the logical file name, like "mydb_data", "mydb_log"?  If so, I
wouldn't fret about it, as these are used for very little (and they do not
need to be unique on your server, only within the set of files for a single
database).  Anyway, you can use ALTER DATABASE after the fact to rename the
individual files.

A
Author
31 Aug 2006 3:32 PM
Johan Sjöström
Yes, exactly. Thanks! ALTER DATABASE worked nicely also.

/Johan


Aaron Bertrand [SQL Server MVP] wrote:
Show quote
> >>
> But when I look at the newdb properties in EM, "Data Files" tab,
> although the locations are correct, the "File Name" is still the
> template db's. Doesn't seem safe to ignore that.
> >>
>
> Do you mean the logical file name, like "mydb_data", "mydb_log"?  If so, I
> wouldn't fret about it, as these are used for very little (and they do not
> need to be unique on your server, only within the set of files for a single
> database).  Anyway, you can use ALTER DATABASE after the fact to rename the
> individual files.
>
> A

AddThis Social Bookmark Button