USE master
GO
DECLARE @LoginName varchar(256)
SET @LoginName ='TangO\Loginame'
SELECT 'USE [' + Name + ']'
+ ';'
+ 'CREATE USER [' + @LoginName + '] FOR LOGIN [' + @LoginName + ']'
+ ';'
+ 'EXEC sp_addrolemember ''db_datareader'', '''+ @LoginName + ''''
AS ScriptToExecute
FROM sys.databases
WHERE name NOT IN ('Master','tempdb','model','msdb','DBAAdmin') -- Avoid System Databases
AND (state_desc ='ONLINE') -- Avoid Offline Databases
AND (source_database_id Is Null) -- Avoid Database Snapshot
ORDER BY Name
No comments:
Post a Comment