|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Yesterday @ 10:17 AM
Points: 133,
Visits: 437
|
|
K. Brian Kelley (8/26/2009) You may want to add a warning that your script is going to turn on xp_cmdshell in order to perform the move. This may balk someone's configuration, especially if policy management is on.
At the bottom of the article it states: Keep in mind this script will kill any connected users by setting the db to single user with SET SINGLE_USER WITH ROLLBACK IMMEDIATE. Anyone connected will be kicked off. The script does set the db back to multi user when it brings the database back online after the move.This script also turns on and uses the xp_cmdshell advanced option. It will set this option back to its original setting (enabled or disabled) at the end of the script.
Jimmy
"I'm still learning the things i thought i knew!"
|
|
|
|
|
Keeper of the Duck
Group: Moderators
Last Login: Yesterday @ 1:55 PM
Points: 6,584,
Visits: 1,789
|
|
imSQrLy (8/26/2009) At the bottom of the article it states: Keep in mind this script will kill any connected users by setting the db to single user with SET SINGLE_USER WITH ROLLBACK IMMEDIATE. Anyone connected will be kicked off. The script does set the db back to multi user when it brings the database back online after the move.This script also turns on and uses the xp_cmdshell advanced option. It will set this option back to its original setting (enabled or disabled) at the end of the script.
Yup, I see that now on a second read-through. I apologize.
K. Brian Kelley, CISA, MCSE, Security+, MVP - SQL Server Regular Columnist (Security), SQLServerCentral.com Author of Introduction to SQL Server: Basic Skills for Any SQL Server User | Professional Development blog | Technical Blog | LinkedIn | Twitter
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 11:22 AM
Points: 5,269,
Visits: 11,207
|
|
just wanted to point out that if using the backup\restore method to move the database files you do not need to delete\rename the database, just use the 'with move' clause in the restore.
---------------------------------------------------------------------
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 8:17 AM
Points: 334,
Visits: 280
|
|
You should add a check for AutoStats. If you set the database to single user and AutoStats gets started you may have problems regaining access. I used a similar approach to merge two databases into one (at 100+ customer sites) and I did run into the problem.
Also, IMHO if you do this often enough to justify writing a stored procedure then you really should have a lot more error checking built into the code.
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Wednesday, April 17, 2013 4:01 AM
Points: 7,
Visits: 26
|
|
Works well in SQL Server 2005, but doesn't in 2000 which returns the error:
EXECUTE cannot be used as a source when inserting into a table variable.
Apparently 2000 doesn't allow the output of a stored procedure to be inserted to a table variable. Would be good to have mentioned this in the article, and would be even better if a solution was suggested!
|
|
|
|
|
SSCarpal Tunnel
       
Group: General Forum Members
Last Login: Today @ 9:05 AM
Points: 4,428,
Visits: 7,207
|
|
Thanks for the article, Jimmy. One thing you might want to consider is that if you have large data files with small amounts of data in them, backup and restore may be the quicker option. This is because backup and restore will only move the data, whereas detach-move-attach will move the whole data files, including empty space. I know that the restore process will also need to create the data file in the new location, but in a test I did on a single disk PC, it took more than 100 times longer to copy a 10GB database file into a new location than it did to create the file in the first place.
John
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Yesterday @ 8:18 AM
Points: 124,
Visits: 471
|
|
What hapens to the index files (NDF) if they exist?
Don't just give the hungry man a fish, teach him how to catch it as well.
the sqlist
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Yesterday @ 10:17 AM
Points: 133,
Visits: 437
|
|
the sqlist (8/27/2009) What hapens to the index files (NDF) if they exist?
The primary and secondary data files are moved as well, to the same location. If you need them to go on different disks you would need to modify the script.
Jimmy
"I'm still learning the things i thought i knew!"
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Friday, October 23, 2009 7:34 AM
Points: 1,
Visits: 23
|
|
| Found an issue with this script, if a Database is off-line ... it will be brought back online without moving the mdf and ldf files.
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Thursday, September 10, 2009 9:04 AM
Points: 1,
Visits: 7
|
|
| Does this move indexes too?
|
|
|
|