[SCRIPT] – Listing Database Users and Roles
I am a fan of not reinventing the wheel. What that means? Well, If I need to do something, which usually involves creating a script, I try first to do a quick search on Google and see if someone already had this idea.
Looking at the title of the article you might say: Oh, that’s easily done with dbatools, which in fact it is true. However, my use case this time was a bit different than the conventional, because I want to expose that dynamically in my Python/Django Internal tool that exposes SQL Server through API’s, so the need for a TSQL script is imminent.
The goal result that I need is:
|User Name||User Type||Create Date||Roles|
Honestly saying, I saw a few solutions, not exactly as I wanted, but the main thing was that they involved the creation of temporary tables and some very messy solution that I personally didn’t like.
So, for those reasons, I personally ended up creating the below script.
The execution of this query produces the following result.
Data Platform MVP
Posted on September 13, 2018, in Dicas, T-SQL and tagged concat database roles for users, concatenante database roles, database roles, database users, list database users and roles, script for database users and roles. Bookmark the permalink. Leave a comment.