Reputation: 701
I have a Database say TestDatabase.I have already added an user under NTAuthority\SYSTEM(Role) Db_owner.
Again i wish to add another user to the same Database under NTAuthority\System with different role.
I received the following error :
The login already has an accoind under different username.
SQL Server Error :15063
How can i add different users to the same database with different role.
I would appreciate if i receive elobarate explanation.
Upvotes: 0
Views: 988
Reputation: 432311
You can't. You add the same user to multiple roles.
db_owner already has all rights anyway withing the database so any other permissions are superfluous.
CREATE USER [NTAuthority\SYSTEM] FROM LOGIN [NTAuthority\SYSTEM];
EXEC sp_addrolemember 'db_owner', 'NTAuthority\SYSTEM'
-- ...and fails
CREATE USER [bob] FROM LOGIN [NTAuthority\SYSTEM];
--Normally, for one user in multiple roles
EXEC sp_addrolemember 'DoStuff', 'NTAuthority\SYSTEM'
EXEC sp_addrolemember 'DoSpecialStuff', 'NTAuthority\SYSTEM'
--... and for another user
EXEC sp_addrolemember 'DoStuff', 'AnotherUser'
--... and for yet another user
EXEC sp_addrolemember 'DoLimitedStuff', 'TheThirdUser'
Edit:
Look at the MS documentation: Database-Level Roles and the parent Identity and Access Control topic
Upvotes: 1
Reputation: 294307
if is db_owner there is no point in adding him to any other role.
to add an existing user to a new role you run sp_roleaddmember
Upvotes: 0