DECLARE @cmd nvarchar(255);
--first create user
SET @cmd = 'IF ''[?]'' NOT IN(''master'', ''model'', ''msdb'', ''tempdb'')
BEGIN USE [?] CREATE USER [domain\user] FOR LOGIN [domain\user]'' END';
EXEC master.sys.sp_MSforeachdb @command1 = @cmd
SET @cmd = 'IF ''[?]'' NOT IN(''master'', ''model'', ''msdb'', ''tempdb'')
BEGIN USE [?] exec sp_addrolemember ''db_owner'', ''Domain\User'' END';
EXEC master.sys.sp_MSforeachdb @command1 = @cmd
No comments:
Post a Comment