Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

detach & reattach sql logins

Status
Not open for further replies.

DLTaylor

MIS
Dec 17, 2003
51
GB
I need to rebuild a database.
To do this in need to detach my logins > then recreate db > then reattach logins.

What is the best way to detach and re attach the logins?
 
Look up sp_addlogin in BOL. Pay special attention to the @sid parameter.
 
Thanks for the pointer.

My real issue stems from the need to remove the logins and then reattach the to the same rebuilt database.

It would be easy if I had a second db that I could move loggings into on a temp basis and then transfer back, but I do not have this luxury - is there a way of detaching loggings and re-attaching without the help of a second db to store the logins?

Thanks
Dan
 
Do you mean change the default database of each login? That is easy enough to do as well. Remember, all of the logins' information is stored in the master database. In going from server to server, the biggest challenge is to keep the sids lined up.
 
You might be able to script off the logins from Enterprise Manager and then run the script on your rebuild. But there isn't any 'detach/attach' like there is for databases.

-SQLBill

Posting advice: FAQ481-4875
 
THIS IS HOW YOU DO IT, look no further:

1.) Script the logins on the ORIGINAL server, using "sp_help_revlogin" stored procedure.

2.) Copy and paste the output of the script to Query Analyzer on the TARGET server.

3.) Restore you database on the TARGET server.

Your logins/users will then be attached!

Very simple. No need to run sp_addlogin, etc, etc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top