I am trying to write a script to grant EXEC permissions on all non-system stored procedures on all DB's to a specific user 'QATest'
The below code will do this successfully but I need a way of writing it so it will run on ALL databases. Avoiding writing the same code for all db's on the system.
Any help?
---------------
declare @sql nvarchar(4000)
declare @db sysname ; set @db = 'Test32' --Change DB NAME
declare @u sysname ; set @u = QUOTENAME('QATest')
set @sql ='select ''grant exec on '' + QUOTENAME(ROUTINE_SCHEMA) + ''.'' +
QUOTENAME(ROUTINE_NAME) + '' TO ' + @u + ''' FROM INFORMATION_SCHEMA.ROUTINES ' +
'WHERE OBJECTPROPERTY(OBJECT_ID(ROUTINE_NAME),''IsMSShipped'') = 0'
PRINT 'Adding EXEC Stored Procedure permissions to ' + @u + ' on data base ' + @db
exec master.dbo.xp_execresultset @sql,@db
The below code will do this successfully but I need a way of writing it so it will run on ALL databases. Avoiding writing the same code for all db's on the system.
Any help?
---------------
declare @sql nvarchar(4000)
declare @db sysname ; set @db = 'Test32' --Change DB NAME
declare @u sysname ; set @u = QUOTENAME('QATest')
set @sql ='select ''grant exec on '' + QUOTENAME(ROUTINE_SCHEMA) + ''.'' +
QUOTENAME(ROUTINE_NAME) + '' TO ' + @u + ''' FROM INFORMATION_SCHEMA.ROUTINES ' +
'WHERE OBJECTPROPERTY(OBJECT_ID(ROUTINE_NAME),''IsMSShipped'') = 0'
PRINT 'Adding EXEC Stored Procedure permissions to ' + @u + ' on data base ' + @db
exec master.dbo.xp_execresultset @sql,@db