2. Right-click on database, select New Query, paste the following code, replace DOMAIN\user with real value, start script:
EXECUTE master.sys.sp_MSforeachdb '
use [?];
declare @user sysname = ''DOMAIN\user''
if db_name() not in (''master'', ''model'', ''msdb'', ''tempdb'')
begin
if not exists (
select null
from dbo.sysusers
where name = @user
)
begin
print ''Adding '' + @user + '' to '' + db_name();
exec sp_grantdbaccess @user, @user;
end;
print ''Granting '' + @user + '' access rights to '' + db_name();
exec sp_addrolemember db_owner, @user;
end;
'
No comments:
Post a Comment