Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

MSSQL – List Users With Permissions

Posted on June 21, 2017June 22, 2017 By David Kittell

Sometimes you really just need to know how many users you have on your database, the below script will give a quick report for your database.

Note: This script is designed to run on a selected database, you will have to select the database first and then run the script.

SELECT 
	@@Servername AS [SQL Server],
	DB_NAME() AS [SQL Database],
	memberdatabaseprincipal.NAME AS [SQL User],
	princ.NAME AS [SQL Role],
	--memberdatabaseprincipal.type_desc AS member_type_desc,
	memberdatabaseprincipal.create_date AS [SQL User Create Date],
	memberdatabaseprincipal.modify_date AS [SQL User Modified Date]
FROM sys.database_principals AS princ
LEFT JOIN sys.database_permissions AS PERM ON PERM.grantee_principal_id = princ.principal_id
INNER JOIN sys.database_role_members AS roles ON roles.role_principal_id = princ.principal_id
INNER JOIN sys.database_principals AS memberdatabaseprincipal ON memberdatabaseprincipal.principal_id = roles.member_principal_id
WHERE memberdatabaseprincipal.NAME NOT IN ('dbo')
ORDER BY [SQL Role],
	[SQL User]
Originally Posted on June 21, 2017
Last Updated on June 22, 2017
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Code MSSQL MSSQL - Audit MSSQL - Azure SQL

Post navigation

Previous post
Next post

Related Posts

Red Hat 8 – Install NGINX Load Balance DNS

Posted on May 17, 2019

Similar to Ubuntu / Raspberry Pi – Install NGINX Load Balance DNS Some prerequisite posts to look at: Should Run Red Hat – Check Subscription / Register Server SELinux Configuration Change UNIX – Set SSH Banner Should Read/Understand UNIX – Bash Identify Distribution (What OS Am I On) UNIX –…

Read More

Ektron Find Replace In Menu

Posted on October 23, 2013October 26, 2015

This script will rename menu link paths SET XACT_ABORT ON DECLARE @currval NVARCHAR(500) DECLARE @newval NVARCHAR(500) DECLARE @search NVARCHAR(500) DECLARE @replace VARCHAR(500) SET @search = ” –string to find SET @replace = ” –replacement string DECLARE @pos INT DECLARE @id BIGINT BEGIN TRAN DECLARE curs CURSOR LOCAL FAST_FORWARD FOR SELECT…

Read More

PowerShell – Create ASPX Site Within IIS Including Dedicated Application Pool

Posted on November 13, 2015November 17, 2015

This script relies on this post currently as it gets a test ASPX site to make sure everything was setup correctly. .\IIS-Create.ps1 <Site/App Name> <Site Root Path> <Site Port> <Domain User Account> <Domain User Password> clear Function Load-WebAdmin { $webAdminModule = get-module -ListAvailable | ? { $_.Name -eq "webadministration" }…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • Open On Screen Keyboard (OSK)
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes