Application.CreateRoleIfNonexistent
Documentation | WideWorldImporters |
Schema | Application |
Name | CreateRoleIfNonexistent |
Input/Output
Mode | Name | Data type | Description | |
---|---|---|---|---|
1 | IN | RoleName | nvarchar(128) |
Script
CREATE PROCEDURE [Application].CreateRoleIfNonexistent @RoleName sysname WITH EXECUTE AS OWNER AS BEGIN SET NOCOUNT ON; SET XACT_ABORT ON; IF NOT EXISTS (SELECT 1 FROM sys.database_principals WHERE name = @RoleName AND type = N'R') BEGIN BEGIN TRY DECLARE @SQL nvarchar(max) = N'CREATE ROLE ' + QUOTENAME(@RoleName) + N';' EXECUTE (@SQL); PRINT N'Role ' + @RoleName + N' created'; END TRY BEGIN CATCH PRINT N'Unable to create role ' + @RoleName; THROW; END CATCH; END; END; |
Exported: 2019-02-04 23:04, Last imported: 2018-08-10 09:51