Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

Newbie - Detach / Attach in SQL 2005 Expand / Collapse
Author
Message
Posted Monday, March 1, 2010 9:06 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Monday, June 30, 2014 8:04 AM
Points: 99, Visits: 447
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!
Post #874478
Posted Monday, March 1, 2010 9:20 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, July 8, 2014 6:32 AM
Points: 1,015, Visits: 1,334
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__
Post #874487
Posted Monday, March 1, 2010 9:23 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Friday, June 20, 2014 7:05 AM
Points: 972, Visits: 3,336
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
Post #874490
Posted Monday, March 1, 2010 9:29 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Monday, June 30, 2014 8:04 AM
Points: 99, Visits: 447
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?
Post #874495
Posted Monday, March 1, 2010 9:32 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Friday, June 20, 2014 7:05 AM
Points: 972, Visits: 3,336
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
Post #874496
Posted Monday, March 1, 2010 9:37 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 8:10 AM
Points: 42,351, Visits: 35,412
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 2008, MVP
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

Post #874505
Posted Monday, March 1, 2010 9:49 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, July 8, 2014 6:32 AM
Points: 1,015, Visits: 1,334
Opps..My mistake!!! No need to stop any service for detach/attach of user DBs...

Renuka__
Post #874513
Posted Monday, March 1, 2010 10:27 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Monday, June 30, 2014 8:04 AM
Points: 99, Visits: 447
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?
Post #874537
Posted Monday, March 1, 2010 10:40 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Friday, June 20, 2014 7:05 AM
Points: 972, Visits: 3,336
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
Post #874543
Posted Monday, March 1, 2010 10:43 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 8:10 AM
Points: 42,351, Visits: 35,412
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 2008, MVP
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

Post #874545
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse