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'
Showing posts with label if exists. Show all posts
Showing posts with label if exists. Show all posts
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:
Posts (Atom)