I have a (SS2005) database with a user named MY_APPLICATION_USER. I'm trying to create a role in that database named MY_APPLICATION_USER.

When I try to do that using this script:

/****** Object:  Role [MY_APPLICATION_USER] ******/

I get the error message:

Msg 15023, Level 16, State 1, Line 2
User, group, or role 'MY_APPLICATION_USER' already exists in the current database.

Does SQL Server have a restriction where it is not allowed to have a user and a role with the same name? I googled various ways of asking that question and did not find anything which addresses this, but it's certainly possible that I missed something.

  • 1
    The error states it rather well: You cannot have a user and role with the same name. They all fall under sys.database_principals. Feb 28 '12 at 16:59
  • I figured that was it but I couldn't find any documentation confirming it. Please put your comment as an answer and I'll accept it. I didn't know where it stores that information and I just assumed roles would be stored separate from the users but now I know better. Feb 28 '12 at 17:08
  • Note this makes perfect sense: otherwise, how can you resolve SomePrincipal in this GRANT .. TO SomePrincipal
    – gbn
    Mar 2 '12 at 15:37

No, you cannot have a User and a Role with the same name. These objects are all stored and referenced in sys.database_principals, requiring they are unique.

sys.database_principals MSDN Reference

Quoted from the name parameter:

name : Name of principal, unique within the database.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.