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


Newbie - Detach / Attach in SQL 2005


Newbie - Detach / Attach in SQL 2005

Author
Message
chrisph
chrisph
SSC-Enthusiastic
SSC-Enthusiastic (143 reputation)SSC-Enthusiastic (143 reputation)SSC-Enthusiastic (143 reputation)SSC-Enthusiastic (143 reputation)SSC-Enthusiastic (143 reputation)SSC-Enthusiastic (143 reputation)SSC-Enthusiastic (143 reputation)SSC-Enthusiastic (143 reputation)

Group: General Forum Members
Points: 143 Visits: 623
Hi all!

I have no DBA experience, this is very new to me coming from desktop support.

I would like to move a database from one server to another. I have read up on it (here and other sites) and looks like using detach/attach through the Studio consel would be my best bet.
It appears most sites recommend this be done through code (TSQL?), but I have no idea even where to begin/invoke this. Others have suggested using backup/restore but this is out of my scope right now. I will be going on course soon but this needs to be done sooner than later.

From what I understand this should work if I:
-Stop SQL Agent service on server #1.
-Detach DB on server #1.
-Copy .mdf and .ldf files from server #1 to #2.
-Attach DB on server #2 using the files.

Could you wizards give me the thumbs up or thumbs down on this or if there is anything else I should do or watch for?

Thanks!
Renuka__
Renuka__
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1024 Visits: 1370
Hi...

Its not the Agent service, but the SQL Server service should be stopped. But, there are other things need to be considered, like - informing the business users about the downtime, check if there are any other servers accessing this database through linked server configuration, checking if users are mapped properly etc.,

Renuka__
AndrewSQLDBA
AndrewSQLDBA
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1008 Visits: 3427
I would recommend using Backup and Restore. Much easier and if something is incorrect, you still have the original database up and running. Also, how do you plan to transfer the logins? The Users in the database will go with the database, but the mating Logins will not. You will have to either transfer them, or drop them all and re-create them on the other box.

All of this is in the SQL Books Online. Have you read any of the material there? If gives you syntax for all SQL code that you need. You can use the SSMS Interface as well if you are comfortable there. Both preform the same tasks. Meaning, a backup command in T-SQL will get you the same thing as if you right click and select Backup from the list.

I would leave the original alone until you get the database on the other box up and running the way you want. That means, using Backup and Restore, or creating an SSMS package to pump everything over. I would also create a full backup of the original just before you begin. You can always restore that if you really need too. But once you have a backup, copy it over to the other box and restore it.

Andrew SQLDBA
chrisph
chrisph
SSC-Enthusiastic
SSC-Enthusiastic (143 reputation)SSC-Enthusiastic (143 reputation)SSC-Enthusiastic (143 reputation)SSC-Enthusiastic (143 reputation)SSC-Enthusiastic (143 reputation)SSC-Enthusiastic (143 reputation)SSC-Enthusiastic (143 reputation)SSC-Enthusiastic (143 reputation)

Group: General Forum Members
Points: 143 Visits: 623
Thanks for the quick replies guys. The DB is just in it's infancy, there is only one login so far, so as far as that goes it shouldn't be a problem. I'll double check with the other guy who does the programming of the DB to see if anything else is being linked to it.
As far as stopping the service, the SQL Server service has to be stopped?
How about the SQL Server Agent service?
AndrewSQLDBA
AndrewSQLDBA
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1008 Visits: 3427
Not when you take a backup. Nothing has to be stopped, and no user has to exit. Just create a Full backup and move the backup file to where ever you like.

Andrew SQLDBA
GilaMonster
GilaMonster
SSC-Forever
SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)

Group: General Forum Members
Points: 47174 Visits: 44353
No services need to be stopped to detach and attach a database. Just note that the DB will be unavailable while the copy is in process.

Backup/restore is a better option, users could carry on using the DB while you're backing it up, no one would notice anything.


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


Renuka__
Renuka__
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1024 Visits: 1370
Opps..My mistake!!! No need to stop any service for detach/attach of user DBs...

Renuka__
chrisph
chrisph
SSC-Enthusiastic
SSC-Enthusiastic (143 reputation)SSC-Enthusiastic (143 reputation)SSC-Enthusiastic (143 reputation)SSC-Enthusiastic (143 reputation)SSC-Enthusiastic (143 reputation)SSC-Enthusiastic (143 reputation)SSC-Enthusiastic (143 reputation)SSC-Enthusiastic (143 reputation)

Group: General Forum Members
Points: 143 Visits: 623
Thanks guys.
Is there a difference as to how user accounts are transfered over using restore vs. detach/attach, or if they are transfered at all?
AndrewSQLDBA
AndrewSQLDBA
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1008 Visits: 3427
Since you said that you have only the one account, I would just re-create it by hand. Much more simple for only the one account.

You will have the original database still up and running if you need to look at any mappings. I would think there are none for only one account. This is most likely the account used in the database connections from the app.

Andrew SQLDBA
GilaMonster
GilaMonster
SSC-Forever
SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)

Group: General Forum Members
Points: 47174 Visits: 44353
Both will transfer the database users. They're stored in the database, hence they move with the database.

Neither will transfer the login information. That you'll have to script out, preferably with the SID (check Books Online for details) and create on the other server.


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


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