Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Create a copy of database with a new name


Create a copy of database with a new name

Author
Message
Mitesh Oswal
Mitesh Oswal
SSC Eights!
SSC Eights! (830 reputation)SSC Eights! (830 reputation)SSC Eights! (830 reputation)SSC Eights! (830 reputation)SSC Eights! (830 reputation)SSC Eights! (830 reputation)SSC Eights! (830 reputation)SSC Eights! (830 reputation)

Group: General Forum Members
Points: 830 Visits: 653
Comments posted to this topic are about the item Create a copy of database with a new name

Regards,
Mitesh OSwal
+918698619998
tskelley
tskelley
Valued Member
Valued Member (65 reputation)Valued Member (65 reputation)Valued Member (65 reputation)Valued Member (65 reputation)Valued Member (65 reputation)Valued Member (65 reputation)Valued Member (65 reputation)Valued Member (65 reputation)

Group: General Forum Members
Points: 65 Visits: 1157
Many thanks! I absolutely loved this. I need to make a copy of my current dev db so many times. This will be a great time saver. I did make a few minor tweaks to the declare section, which I think make it more readable/usable (but I know this can always be a bit subjective). :-)


DECLARE @FirstDBName NVARCHAR(100) = 'Mitesh01'
DECLARE @NewDBName NVARCHAR(100) = 'Mitesh02'
DECLARE @BackupLocation NVARCHAR(100) = 'C:\Backup\'

DECLARE@fileName NVARCHAR(1000)
SELECT @fileName = @BackupLocation+@FirstDBName+REPLACE(REPLACE(REPLACE(CONVERT(VARCHAR(16),SYSDATETIMEOFFSET(),120),'-',''),':',''),' ','')+'.bak'






terry.home
terry.home
SSC Rookie
SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)

Group: General Forum Members
Points: 44 Visits: 188
I like what you have done although I have not tried running the script yet.

Ideally I would like to copy the database to another server, not onto the same server (normally to be used for reporting purposes).

In my (limited) experience I have had to run one job to do the backup, then a seperate scheduled task that (via batch job) copies the backup file to remote server, then a seperate agent task scheduled to run about an hour later that restores the file on that server.

If there is a way to run just one script, that does the backup, then restores the file on the remote server, that would be even better.

T
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search