2

When I’m trying to create a role then I receive the error “role exists” and I have to deleted first and repeat the process.

  • How may I check if a role exists in my sql database in sql server 2008 r2?
  • Is there any sys.table to search for it?
Chris
  • 8,527
  • 10
  • 34
  • 51
Lefteris Gkinis
  • 1,229
  • 6
  • 26
  • 63
  • 2
    possible duplicate of [How do I determine if a database role exists in SQL Server?](http://stackoverflow.com/questions/1201160/how-do-i-determine-if-a-database-role-exists-in-sql-server) – Chris Sep 08 '13 at 14:08
  • Yes but in this table `database_principals` are only the roles which the system create... what about the roles I have create? where I'll found them? – Lefteris Gkinis Sep 08 '13 at 14:21

1 Answers1

1

use sys.database_principals view:

select * from sys.database_principals where name = @Role_Name and type = 'R'

it's also possible to use database_principal_id:

select database_principal_id(@Role_Name)
Roman Pekar
  • 107,110
  • 28
  • 195
  • 197
  • Yes but in this table `sys.database_principals` are only the roles which the system create... what about the roles which I have create? where I'll found them? – Lefteris Gkinis Sep 08 '13 at 14:22
  • you'll find them in sys.database_principals - try it. – Roman Pekar Sep 08 '13 at 14:32
  • Yes you have right... the reason that i didn't find it there was that I didn't add a `schema` to the role... thats why I'm not seen it in view `sys.database_principals` – Lefteris Gkinis Sep 08 '13 at 14:37