﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Article Discussions / Article Discussions by Author / Discuss content posted by James DiMauro  / Moving Databases with the ALTER Command / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sun, 19 May 2013 00:28:51 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Moving Databases with the ALTER Command</title><link>http://www.sqlservercentral.com/Forums/Topic777288-1335-1.aspx</link><description>Does this move indexes too?</description><pubDate>Fri, 04 Sep 2009 12:52:46 GMT</pubDate><dc:creator>computercio</dc:creator></item><item><title>RE: Moving Databases with the ALTER Command</title><link>http://www.sqlservercentral.com/Forums/Topic777288-1335-1.aspx</link><description>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.</description><pubDate>Thu, 27 Aug 2009 11:39:43 GMT</pubDate><dc:creator>thehumansponge</dc:creator></item><item><title>RE: Moving Databases with the ALTER Command</title><link>http://www.sqlservercentral.com/Forums/Topic777288-1335-1.aspx</link><description>[quote][b]the sqlist (8/27/2009)[/b][hr]What hapens to the index files (NDF) if they exist?[/quote]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.</description><pubDate>Thu, 27 Aug 2009 11:07:30 GMT</pubDate><dc:creator>imSQrLy</dc:creator></item><item><title>RE: Moving Databases with the ALTER Command</title><link>http://www.sqlservercentral.com/Forums/Topic777288-1335-1.aspx</link><description>What hapens to the index files (NDF) if they exist?</description><pubDate>Thu, 27 Aug 2009 10:07:53 GMT</pubDate><dc:creator>the sqlist</dc:creator></item><item><title>RE: Moving Databases with the ALTER Command</title><link>http://www.sqlservercentral.com/Forums/Topic777288-1335-1.aspx</link><description>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</description><pubDate>Thu, 27 Aug 2009 02:35:33 GMT</pubDate><dc:creator>John Mitchell-245523</dc:creator></item><item><title>RE: Moving Databases with the ALTER Command</title><link>http://www.sqlservercentral.com/Forums/Topic777288-1335-1.aspx</link><description>Works well in SQL Server 2005, but doesn't in 2000 which returns the error:[quote]EXECUTE cannot be used as a source when inserting into a table variable.[/quote]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!</description><pubDate>Wed, 26 Aug 2009 20:01:27 GMT</pubDate><dc:creator>el-slo</dc:creator></item><item><title>RE: Moving Databases with the ALTER Command</title><link>http://www.sqlservercentral.com/Forums/Topic777288-1335-1.aspx</link><description>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.</description><pubDate>Wed, 26 Aug 2009 16:35:22 GMT</pubDate><dc:creator>Ray Herring</dc:creator></item><item><title>RE: Moving Databases with the ALTER Command</title><link>http://www.sqlservercentral.com/Forums/Topic777288-1335-1.aspx</link><description>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.</description><pubDate>Wed, 26 Aug 2009 16:01:54 GMT</pubDate><dc:creator>george sibbald</dc:creator></item><item><title>RE: Moving Databases with the ALTER Command</title><link>http://www.sqlservercentral.com/Forums/Topic777288-1335-1.aspx</link><description>[quote][b]imSQrLy (8/26/2009)[/b][hr]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.[/quote]Yup, I see that now on a second read-through. I apologize.</description><pubDate>Wed, 26 Aug 2009 13:36:52 GMT</pubDate><dc:creator>K. Brian Kelley</dc:creator></item><item><title>RE: Moving Databases with the ALTER Command</title><link>http://www.sqlservercentral.com/Forums/Topic777288-1335-1.aspx</link><description>[quote][b]K. Brian Kelley (8/26/2009)[/b][hr]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.[/quote]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.</description><pubDate>Wed, 26 Aug 2009 12:51:31 GMT</pubDate><dc:creator>imSQrLy</dc:creator></item><item><title>RE: Moving Databases with the ALTER Command</title><link>http://www.sqlservercentral.com/Forums/Topic777288-1335-1.aspx</link><description>[quote][b]rondad (8/26/2009)[/b][hr]Has anyone tested the script with using a unc path for the new target location rather than a "hard-coded" drive letter?Ron[/quote]I have not tested it like that.</description><pubDate>Wed, 26 Aug 2009 12:49:33 GMT</pubDate><dc:creator>imSQrLy</dc:creator></item><item><title>RE: Moving Databases with the ALTER Command</title><link>http://www.sqlservercentral.com/Forums/Topic777288-1335-1.aspx</link><description>[quote][b]Private Gripweed (8/26/2009)[/b][hr]The script works well with one exception. If your logical name for the database files contains spaces, it will cause issues. If you alter the stored procedure and enclose the logical name for the database file in double quotes, this fixes the issue. See below:set @sql = 'ALTER DATABASE ' + @DbName + ' MODIFY FILE (NAME = "' + @LogicalName + '", FILENAME = "' + @NewPath   + '")'[/quote]Thanks for pointing that out. I will update my script.</description><pubDate>Wed, 26 Aug 2009 12:48:57 GMT</pubDate><dc:creator>imSQrLy</dc:creator></item><item><title>RE: Moving Databases with the ALTER Command</title><link>http://www.sqlservercentral.com/Forums/Topic777288-1335-1.aspx</link><description>[quote][b]Johan van Tonder (8/26/2009)[/b][hr]Very good method.I'm just not sure if I would want to be any one of the users connected to the DB while the script is run, since I will get killed ;-)[quote]Keep in mind this script will kill any connected users by setting the db to single user with SET SINGLE_USER WITH ROLLBACK IMMEDIATE[/quote]Yes, I know what's being meant, but that gave me laugh though :-)[/quote]Bang your dead!I haven't laughed like this all week.</description><pubDate>Wed, 26 Aug 2009 12:47:54 GMT</pubDate><dc:creator>imSQrLy</dc:creator></item><item><title>RE: Moving Databases with the ALTER Command</title><link>http://www.sqlservercentral.com/Forums/Topic777288-1335-1.aspx</link><description>EDIT: Brian needs to read more closely. :)</description><pubDate>Wed, 26 Aug 2009 12:11:31 GMT</pubDate><dc:creator>K. Brian Kelley</dc:creator></item><item><title>RE: Moving Databases with the ALTER Command</title><link>http://www.sqlservercentral.com/Forums/Topic777288-1335-1.aspx</link><description>Easily tested.  But I have not</description><pubDate>Wed, 26 Aug 2009 11:54:35 GMT</pubDate><dc:creator>Private Gripweed</dc:creator></item><item><title>RE: Moving Databases with the ALTER Command</title><link>http://www.sqlservercentral.com/Forums/Topic777288-1335-1.aspx</link><description>Has anyone tested the script with using a unc path for the new target location rather than a "hard-coded" drive letter?Ron</description><pubDate>Wed, 26 Aug 2009 11:41:14 GMT</pubDate><dc:creator>rondad</dc:creator></item><item><title>RE: Moving Databases with the ALTER Command</title><link>http://www.sqlservercentral.com/Forums/Topic777288-1335-1.aspx</link><description>LOL that is funny, I did not think about it that way. </description><pubDate>Wed, 26 Aug 2009 11:27:28 GMT</pubDate><dc:creator>Private Gripweed</dc:creator></item><item><title>RE: Moving Databases with the ALTER Command</title><link>http://www.sqlservercentral.com/Forums/Topic777288-1335-1.aspx</link><description>Very good method.I'm just not sure if I would want to be any one of the users connected to the DB while the script is run, since I will get killed ;-)[quote]Keep in mind this script will kill any connected users by setting the db to single user with SET SINGLE_USER WITH ROLLBACK IMMEDIATE[/quote]Yes, I know what's being meant, but that gave me laugh though :-)</description><pubDate>Wed, 26 Aug 2009 11:13:01 GMT</pubDate><dc:creator>Johan van Tonder</dc:creator></item><item><title>RE: Moving Databases with the ALTER Command</title><link>http://www.sqlservercentral.com/Forums/Topic777288-1335-1.aspx</link><description>The script works well with one exception. If your logical name for the database files contains spaces, it will cause issues. If you alter the stored procedure and enclose the logical name for the database file in double quotes, this fixes the issue. See below:set @sql = 'ALTER DATABASE ' + @DbName + ' MODIFY FILE (NAME = "' + @LogicalName + '", FILENAME = "' + @NewPath   + '")'</description><pubDate>Wed, 26 Aug 2009 10:12:40 GMT</pubDate><dc:creator>Private Gripweed</dc:creator></item><item><title>Moving Databases with the ALTER Command</title><link>http://www.sqlservercentral.com/Forums/Topic777288-1335-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/articles/ALTER+DATABASE+MODIFY+FILE/67527/"&gt;Moving Databases with the ALTER Command&lt;/A&gt;[/B]</description><pubDate>Wed, 26 Aug 2009 00:18:09 GMT</pubDate><dc:creator>imSQrLy</dc:creator></item></channel></rss>