Posts

Showing posts from August, 2019

SQL Server Extract User Roles and Build queries

Need to export all users and it's object-level permissions at one go? then execute the below to generate the Queries for creating the users and granting permissions at one go. Courtesy:  https://dba.stackexchange.com DECLARE     @sql VARCHAR(2048)     ,@sort INT DECLARE tmp CURSOR FOR /*********************************************/ /*********   DB CONTEXT STATEMENT    *********/ /*********************************************/ SELECT '-- [-- DB CONTEXT --] --' AS [-- SQL STATEMENTS --],         1 AS [-- RESULT ORDER HOLDER --] UNION SELECT  'USE' + SPACE(1) + QUOTENAME(DB_NAME()) AS [-- SQL STATEMENTS --],         1 AS [-- RESULT ORDER HOLDER --] UNION SELECT '' AS [-- SQL STATEMENTS --],         2 AS [-- RESULT ORDER HOLDER --] UNION /*********************************************/ /*********     DB USER CREATION      *...