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


Detach & Attach Procedure


Detach & Attach Procedure

Author
Message
Vimal Lohani
Vimal Lohani
SSChasing Mays
SSChasing Mays (660 reputation)SSChasing Mays (660 reputation)SSChasing Mays (660 reputation)SSChasing Mays (660 reputation)SSChasing Mays (660 reputation)SSChasing Mays (660 reputation)SSChasing Mays (660 reputation)SSChasing Mays (660 reputation)

Group: General Forum Members
Points: 660 Visits: 659
Comments posted to this topic are about the item Detach & Attach Procedure

Vimal Lohani
SQL DBA | MCP (70-461,70-462)

==============================
The greatest barrier to success is the fear of failure
** Success is a journey not a destination
**

Think before you print, SAVE TREES, Protect Mother Nature
Perry Whittle
Perry Whittle
SSC Guru
SSC Guru (70K reputation)SSC Guru (70K reputation)SSC Guru (70K reputation)SSC Guru (70K reputation)SSC Guru (70K reputation)SSC Guru (70K reputation)SSC Guru (70K reputation)SSC Guru (70K reputation)

Group: General Forum Members
Points: 70750 Visits: 17847
What's wrong with just using sp_detach_db and create database for attach?

If all you're doing here is detaching to move files then this is totally unnecessary anyway and is an old hangover from sql server 2000.

To move files simply offline the database and use

alter database ... Modify file ...



Please see my article at this link for more info

-----------------------------------------------------------------------------------------------------------

"Ya can't make an omelette without breaking just a few eggs" ;-)
Vimal Lohani
Vimal Lohani
SSChasing Mays
SSChasing Mays (660 reputation)SSChasing Mays (660 reputation)SSChasing Mays (660 reputation)SSChasing Mays (660 reputation)SSChasing Mays (660 reputation)SSChasing Mays (660 reputation)SSChasing Mays (660 reputation)SSChasing Mays (660 reputation)

Group: General Forum Members
Points: 660 Visits: 659
Sure. @Perry Whittle,

But what, if you have more than 50 or 100 databases or each database has multiple ldf & log files.
Will you write the query.

The script is for those server. I created this script for my production & successfully detach & attach 66 databases each had 4 or 5 files.

Vimal Lohani
SQL DBA | MCP (70-461,70-462)

==============================
The greatest barrier to success is the fear of failure
** Success is a journey not a destination
**

Think before you print, SAVE TREES, Protect Mother Nature
Perry Whittle
Perry Whittle
SSC Guru
SSC Guru (70K reputation)SSC Guru (70K reputation)SSC Guru (70K reputation)SSC Guru (70K reputation)SSC Guru (70K reputation)SSC Guru (70K reputation)SSC Guru (70K reputation)SSC Guru (70K reputation)

Group: General Forum Members
Points: 70750 Visits: 17847
yes, you can script the alter database commands quite easily using the system catalog sys.master_files ;-)

-----------------------------------------------------------------------------------------------------------

"Ya can't make an omelette without breaking just a few eggs" ;-)
Iwas Bornready
Iwas Bornready
One Orange Chip
One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)

Group: General Forum Members
Points: 25226 Visits: 885
Though we do this, we don't have many databases to make it worthwhile. Thanks for the script work anyway.
Charles Kincaid
Charles Kincaid
Hall of Fame
Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)

Group: General Forum Members
Points: 3781 Visits: 2384
I like to have my main data files and log files on different physical drives. Your script will put all of the files for a database in the same place.

Still is you have to move a whole bunch of databases and are forced (by short sighted managers) to put all the files for a database in the same spot then this can be a great script.

I agree with the other folks that a better way to move files is through ALTER DATABASE. I had never taken them off-line, or put them in single user mode first. I guess that those are both good ideas.

One other down side is that you have to enable the command shell. You will turn that off at the end of the script. That could cause something else that relies on the shell to break when you turn it off. I know it's not a good thing to have on so not having to use it would be a good thing. Another reason to use ALTER DATABASE.

Take some tips for improvement and re-post. Good work.

ATBCharles Kincaid
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