Monday, March 26, 2012

Restore database without providing a name?/

Is there anyway I can restore a database without having to provide a
database name in the restore command? I have a utility that I wrote
to restore my database, but right now I hardcode the database name
into the restore command. Is it possible for the restore command to
just figure out the name of the database on its own so I don't have to
provide it? I'd like my utility to be able to restore databases with
different names and I don't want to have to prompt the user to enter
one.
Any suggestions?
Check out the following commands:
RESTORE HEADERONLY FROM DISK =3D 'x:\foo.bak'
RESTORE FILELISTONLY FROM DISK =3D 'x:\foo.bak'
You will see a column named DatabaseName is returned from the first =
statement. This is the name of the database that was backed up. =20
What if the user does not want to overwrite their database? What if =
they want to perform the restore as a new name so that they can compare =
their current version of foo to the previous version of foo (that they =
restore as Oldfoo)?
--=20
Keith
"Ray Lavelle" <bostonpartykid@.yahoo.com> wrote in message =
news:d8653140.0405201136.11fd6bc3@.posting.google.c om...
> Is there anyway I can restore a database without having to provide a
> database name in the restore command? I have a utility that I wrote
> to restore my database, but right now I hardcode the database name
> into the restore command. Is it possible for the restore command to
> just figure out the name of the database on its own so I don't have to
> provide it? I'd like my utility to be able to restore databases with
> different names and I don't want to have to prompt the user to enter
> one.
> Any suggestions?
|||Thanks, this is exactly what I was looking for!
To answer your question, my application uses a fixed database name so
it has to be restored with the same name as it was backed up with or
my program won't even recognize it. I'm now adding a couple more
databases to support new additions to the product so I need to be able
to back those up also.
"Keith Kratochvil" <sqlguy.back2u@.comcast.net> wrote in message news:<#b#NLKqPEHA.3988@.tk2msftngp13.phx.gbl>...[vbcol=seagreen]
> Check out the following commands:
> RESTORE HEADERONLY FROM DISK = 'x:\foo.bak'
> RESTORE FILELISTONLY FROM DISK = 'x:\foo.bak'
> You will see a column named DatabaseName is returned from the first
> statement. This is the name of the database that was backed up.
>
> What if the user does not want to overwrite their database? What if
> they want to perform the restore as a new name so that they can compare
> their current version of foo to the previous version of foo (that they
> restore as Oldfoo)?
> --
> Keith
>
> "Ray Lavelle" <bostonpartykid@.yahoo.com> wrote in message
> news:d8653140.0405201136.11fd6bc3@.posting.google.c om...

No comments:

Post a Comment