Saturday, 4 April 2020

Provide Permission to all procedures and tables in Database

Following script will help you to create Grant SQL for all the procedures and Tables in your Database.

Procedures:
SELECT
  ' Grant Execute on  '+s.name+'.'+pr.name +'  to YourGroup/UserName'
FROM
    [DatabaseName].sys.procedures pr
INNER JOIN
    [DatabaseName].sys.schemas s ON pr.schema_id = s.schema_id;


Tables:
SELECT
'Grant Select,Insert,update,Alter,References,Delete on '+s.name+'.'+t.name+' to YourGroup/UserName'
  FROM sys.tables AS t
  INNER JOIN sys.schemas AS s
  ON t.[schema_id] = s.[schema_id]
  where t.name like 't_%'

-Pushparaj

No comments: