SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Detach and Attach database move filegroup


Detach and Attach database move filegroup

Author
Message
arnold-491793
arnold-491793
SSC Rookie
SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)

Group: General Forum Members
Points: 27 Visits: 97
Experts,

I need your advice with regards to the action i am planning to do during my maintenance activity. I never did this before and need your expert advice.

I am going to move my 2 mdf and 1 ndf file in my filegroup located in my drive E to other drive partition.
Please advice if my steps are correct and will not have any lost data in my transaction logs.

1. Detach mydb
2. move 2 mdf and 1 ndf file to drive F which has more space.
3. Attach mydb with the new filegroup drive location which is F:\...

Please advice if this process will not cause me any lost data in the transaction logs.

Thanks.

Arnet
SQLRNNR
SQLRNNR
SSC-Dedicated
SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)

Group: General Forum Members
Points: 33382 Visits: 18560
I suggest two more things before starting any of that.

1. Backup the database
2. Disable access to the server for all connections not related to you, the team, or whomever is working on the project for the duration of the project.

And then of course, make sure to do it during a maintenance window.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

arnold-491793
arnold-491793
SSC Rookie
SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)

Group: General Forum Members
Points: 27 Visits: 97
CirquedeSQLeil (3/17/2010)
I suggest two more things before starting any of that.

1. Backup the database
2. Disable access to the server for all connections not related to you, the team, or whomever is working on the project for the duration of the project.

And then of course, make sure to do it during a maintenance window.


Thanks for your suggestion.

Is this mean that I will not have any data lost after doing this once i did the procedures mentioned?

Thanks,
Arnet
SQLRNNR
SQLRNNR
SSC-Dedicated
SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)

Group: General Forum Members
Points: 33382 Visits: 18560
If you follow all these steps, you should be fine as far as data loss goes.

In other words, you will have your bases covered and should be protected against data loss.

I might add one more step to the backup - copy the backup to another server somewhere (thus have two copies). This is an extra precautionary step.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

arnold-491793
arnold-491793
SSC Rookie
SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)

Group: General Forum Members
Points: 27 Visits: 97
CirquedeSQLeil (3/17/2010)
If you follow all these steps, you should be fine as far as data loss goes.

In other words, you will have your bases covered and should be protected against data loss.

I might add one more step to the backup - copy the backup to another server somewhere (thus have two copies). This is an extra precautionary step.


Thanks for your wonderful advice. This will make me comfortable now.
SQLRNNR
SQLRNNR
SSC-Dedicated
SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)

Group: General Forum Members
Points: 33382 Visits: 18560
You're welcome.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

JDixon-385826
JDixon-385826
Old Hand
Old Hand (309 reputation)Old Hand (309 reputation)Old Hand (309 reputation)Old Hand (309 reputation)Old Hand (309 reputation)Old Hand (309 reputation)Old Hand (309 reputation)Old Hand (309 reputation)

Group: General Forum Members
Points: 309 Visits: 209
running the below alter DB restricted user will make sure all transactions have been completed before the detach. Running something like the below will make sure you have as little issue as possible

USE MASTER
GO
BACKUP DATABASE DBName
TO...
GO
ALTER DATABASE DBName SET RESTRICTED_USER WITH ROLLBACK IMMEDIATE

BACKUP DATABASE DBName
TO...
WITH DIFFERENTIAL

SP_DETACH_DB 'DBName'

GO

XP_CMDSHELL 'COPY file1'
XP_CMDSHELL 'COPY file2'
XP_CMDSHELL 'COPY file3'
GO
SP_Attach_DB 'DBName', 'File1', ...
GO
ALTER DATABASE DBName SET MULTI_USER WITH ROLLBACK IMMEDIATE
GO
GilaMonster
GilaMonster
SSC Guru
SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)

Group: General Forum Members
Points: 90307 Visits: 45284
You cannot lose data in a detach/attach. SQL Server supports the ACID requirements for relational databases. D stands for durability, meaning once a transaction has committed, the changes that transaction made are durable and will not be lost.

Sure, take a backup in case something goes wrong and tell the users that the app won't be available for the period, but that's just good common sense.

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


GTR
GTR
Right there with Babe
Right there with Babe (757 reputation)Right there with Babe (757 reputation)Right there with Babe (757 reputation)Right there with Babe (757 reputation)Right there with Babe (757 reputation)Right there with Babe (757 reputation)Right there with Babe (757 reputation)Right there with Babe (757 reputation)

Group: General Forum Members
Points: 757 Visits: 368
JDixon-385826 (3/17/2010)
running the below alter DB restricted user will make sure all transactions have been completed before the detach. Running something like the below will make sure you have as little issue as possible

USE MASTER
GO
BACKUP DATABASE DBName
TO...
GO
ALTER DATABASE DBName SET RESTRICTED_USER WITH ROLLBACK IMMEDIATE

BACKUP DATABASE DBName
TO...
WITH DIFFERENTIAL

SP_DETACH_DB 'DBName'

GO

XP_CMDSHELL 'COPY file1'
XP_CMDSHELL 'COPY file2'
XP_CMDSHELL 'COPY file3'
GO
SP_Attach_DB 'DBName', 'File1', ...
GO
ALTER DATABASE DBName SET MULTI_USER WITH ROLLBACK IMMEDIATE
GO


I would exclude this step, won't make any difference.

BACKUP DATABASE DBName
TO...
WITH DIFFERENTIAL

EnjoY!
JDixon-385826
JDixon-385826
Old Hand
Old Hand (309 reputation)Old Hand (309 reputation)Old Hand (309 reputation)Old Hand (309 reputation)Old Hand (309 reputation)Old Hand (309 reputation)Old Hand (309 reputation)Old Hand (309 reputation)

Group: General Forum Members
Points: 309 Visits: 209
well I agree you do not need the diff backup but if you want to be 100% forsure you covered all basis I would keep it:-D
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