tags:

views:

28

answers:

3

Is there a SQL Server command to connect a user of a single database to a login for the database server of the same name?

here's the example:

Database Server - Default Instance Database: TestDB

Server Login - TestUser Existing user on TestDB - TestUser

If I try to make the TestUser login a user of the TestDB database, the "User, group, or role" already exists.

Does anybody know of an easy way to assign the user to the login?

+2  A: 

I think its sp_change_users_login its been a little while but used to do that when detaching and reataching databases

http://msdn.microsoft.com/en-us/library/ms174378.aspx

Gratzy
Thank you - forgot about that sp...worked like a charm
jkelley
+2  A: 

I've used the sp_change_users_login procedure to accomplish, I think, that scenario.

joelt
+2  A: 

The new way is to use ALTER USER

ALTER USER OrphanUser WITH LOGIN = correctedLoginName
gbn
Is this new per SQL2008?
jkelley
Since SQL Server 2005. Gratzy's link refers to this actually.
gbn
Here's the ref: http://msdn.microsoft.com/en-us/library/ms176060.aspx
jkelley
Thank you: I thought I'd posted that link!
gbn
I didn't know about ALTER USER, thanks its been a while since I've had the need.
Gratzy