DECLARE @Role varchar(20) = 'UserRole'
IF NOT EXISTS (SELECT name FROM sysusers
WHERE issqlrole=1 AND name = @Role)
EXEC sp_addrole @Role; --EXEC sp_addrole @Role, 'dbo'
Add DB Role IF NOT EXISTS
Check if the Database Role exists before creating it:
Labels:
add,
create,
database,
db,
if exists,
if not exists,
role,
sp_addrole,
tsql
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment