How do I determine if a database role exists in SQL Server?

后端 未结 2 1314
没有蜡笔的小新
没有蜡笔的小新 2020-12-30 18:43

I\'m trying to figure out how I can check if a database role exists in SQL Server. I want to do something like this:

if not exists (select 1 from sometable          


        
2条回答
  •  难免孤独
    2020-12-30 19:15

    if not exists (select 1 from sys.database_principals where name='role' and Type = 'R')
    begin
    CREATE ROLE role
        AUTHORIZATION MyUser;
    end
    

提交回复
热议问题