Scripting User Level Permission SQL2005

Written by Sugeshkumar Rajendran. Posted in Scripts

This script gives a out script that can be used to script out the existing user permissions in a database.This is compatible only to SQL 2005.

Script

SET NOCOUNT ON
PRINT 'Column Level Privileges to the User:'
SELECT 'grant '+privilege_type+' on '+table_schema+'.'+table_name+' ('+column_name+') to ['+grantee+']'+
CASE IS_GRANTABLE WHEN 'YES' THEN ' With GRANT OPTION'
ELSE '' END FROM INFORMATION_SCHEMA.COLUMN_PRIVILEGES
PRINT 'Table Level Privileges to the User:'
SELECT 'grant '+privilege_type+' on '+table_schema+'.'+table_name+' to ['+grantee+']' +
CASE IS_GRANTABLE WHEN 'YES' THEN ' With GRANT OPTION'
ELSE '' END FROM INFORMATION_SCHEMA.TABLE_PRIVILEGES
PRINT 'Privileges for Procedures/Functions to the User:'
SELECT 'grant execute on '+c.name+'.'+a.name+' to '+USER_NAME(b.grantee_principal_id)+
CASE STATE WHEN 'W' THEN ' with grant option'
ELSE '' END FROM sys.all_objects a, sys.database_permissions b, sys.schemas c
WHERE a.object_id = b.major_id AND a.type IN ('P','FN') AND b.grantee_principal_id<>0
AND b.grantee_principal_id <>2 AND a.schema_id=c.schema_id 
VN:F [1.9.20_1166]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.20_1166]
Rating: 0 (from 0 votes)

Tags: , ,

Trackback from your site.

Leave a comment

*

Recent Comments

VidhyaSagar

|

You can make use of Cluster.exe utility or powershell.

Cluster.exe sample
cluster group “Cluster Group” /move

Powershell sample
Move-ClusterGroup “Cluster Group”

Ganapathy

|

Vidya,

How to move the Windows cluster from one node to the other node in command line

Senthilsjc

|

Usefull Session. Please Keep it up,,

veeresh

|

Not yet tested might be very good feature..

VidhyaSagar

|

Probably Encryption might be set, so go to reporting server configuration wizard and then click on Encryption tab. Once you are there take a backup of the existing key and then delete it. Now you will be able to point it to new db