Andreas Wolter
  • Consulting & Services
    • SQL Server Security Assessment by Andreas Wolter
    • SQL Server Health Check
    • Performance Analysis
    • SQL Server Discovery
    • Air-Gapped SQL Server
  • My Customers
  • About
    • Conferences
    • Certifications
    • Training
  • Blog
  • Contact
  • Click to open the search input field Click to open the search input field Search
  • Menu Menu

Security-Check-Script & Survey: SQL Server Security – Database-Owners, critical Permissions and role membership

Security-Check-Script & Survey:

SQL Server Security – Database-Owners, critical Permissions and role membership

In this survey, I would like to explore in a greater radius which accounts are typically used as database owners. I will subsequently publish the cumulated results here to share them with the community together with some recommendations for hardening security.

In this instance, particular server-wide permissions both of the used account as well as, in case of membership of a (custom) Server Role, critical permissions of that role, are of interest.

Those who have followed my presentations on the topic “Security in SQL Server” in the last years, and especially the „SQL Server Attacked“ series launched in the summer of 2013, may remember how I had also demonstrated there how to break out of a database and be granted full system rights (“Elevation of privileges”), – based on a combination of database owner, configuration and impersonation.

Here, I am providing a T-SQL Script which

  • Identifies the respective database owners of all databases
  • Detects invalid/missing database owners
  • Indicates whether the owner directly possesses security-critical system-wide rights
  • Indicates membership in high privilege Server Roles – including the user defined Server Roles (possible since SQL 2012)
  • Indicates the critical database configurations “trustworthy” and “database chaining”.

Here you can find the script:

https://andreas-wolter.com/downloads/1312_database_owner_permissions_roles.sql.txt (you can remove the .txt after downloading.)

  • It should be working on all SQL Servers since the 2005 version (tested: 2008-2014).

For the purpose of the survey, I would like to ask you to post the anonymized results (preferably in excel-format) here in the comments.

For anonymization purposes, you can simply leave out the last three columns from the result set – these are not of use to a data collection and only meant for your internal usage :-).

Here, you can see a sample result:

The script does not permanently save any data in the system and removes its temporary intermediary results by itself.

I hope you find the report useful and I hope you can share the (anonymized) results with the community. I will not store or use any email but only use the anonymized Query-results.

Thank you in advance for your participation and support of the community! I promise to publish the results with according details on best & bad practices in the next months.


Andreas

Tags: Permissions

Categories: Security - Scripts & Tools

Share
  • Share on Facebook
  • Share on X
  • Share on LinkedIn
8 replies
  1. dadanga says:
    25. June 2026 at 4:01

    damn that ‘SQL Server Attacked’ series breakout demonstration you mentioned sounds so crazy fr!! detecting invalid or missing database owners automatically with this script is literally everything … do you think the results vary a lot when running this on sql server 2014 vs newer versions??

    Reply
    • Andreas Wolter says:
      25. June 2026 at 18:20

      From what I have seen, the results depend on how well the SQL Server is managed. 2014 is long out of support, so that may be an indicator for mixed results. But other than that it’s not really something that has changed a lot over time. Unfortunately, there is still no easy way to avoid ‘sa’, simply for reliability reasons.

      Reply
  2. bit says:
    9. May 2026 at 20:58

    This is a very relevant topic because database owner assignments are often overlooked until a security incident happens. I find the focus on role memberships and privilege escalation especially important. I’m wondering, in real-world environments, which misconfiguration do you encounter most frequently that leads to elevated SQL Server security risks?

    Reply
    • Andreas Wolter says:
      11. May 2026 at 19:01

      Thanks for the thoughtful questions. These topics go quite deep and really depend on the specifics of the environment, especially around ownership, service accounts, and privilege boundaries.

      I’ve written about an initial set of manual checks I typically use here:
      https://passdatacommunitysummit.com/about/news/speaker-blog-post-when-sql-server-security-looks-fine-what-i-look-at-first/

      Another useful resource is the Get-Safe SQL Server assessment script, which I recently published as part of the Sarpedon SQL Server Security Community work: https://sarpedonqualitylab.us/resources/

      Reply
  3. Tasin says:
    26. April 2022 at 14:55

    Hi, is the script still available?

    Reply
    • Andreas Wolter says:
      27. January 2026 at 20:38

      Hi
      it took me a long time to revisit this. It is now here: https://andreas-wolter.com/downloads/1312_database_owner_permissions_roles.sql.txt

      Reply
  4. Andreas Wolter says:
    2. January 2014 at 23:16

    Sure, that’s fine.
    Great, thanks.

    Reply
  5. Eric J. says:
    2. January 2014 at 23:05

    hope this works, too, for my only 4 production dbs

    db_1 0 0 valid sa NULL sysadmin (!) NULL
    db_2 0 0 valid sa NULL sysadmin (!) NULL
    db_3 1 0 valid sa NULL sysadmin (!) NULL
    db_4 0 0 not valid (!) other account NULL sysadmin (!) NULL

    thanx

    Reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Security Assessment Community Edition

Learn about my free Community Edition script.

Recent
  • Sample result in SSMS: local NTLM connections over shared memory from SQL01, and NTLM connections over TCP from a reporting server, an ETL server and a workstation
    NTLM Deprecation and SQL Server: How to Find NTLM Connections...18. November 2026 - 17:01in: Security
  • SQL Server Consolidation: $3M+ in Projected Savings and...30. September 2026 - 15:47in: Architecture & High Availability, Security
  • Using a Database Server as a Honeypot for Threat Detect...18. September 2026 - 16:00in: Security
  • Azure Arc for SQL Server: “Least Privilege” Mode Still...8. September 2026 - 15:56in: Security
  • When SIEM Enrichment Becomes False Attribution3. September 2026 - 14:26in: Security
Comments
  • Thanks Scott. Goof feedback. NETSTAT is a useful addition,...21. November 2026 - 15:44 by Andreas Wolter
  • I would go a little deeper with how to troubleshoot SQL...21. November 2026 - 15:15 by Scott O
  • Protecting database data at rest is essential for maintaining...21. October 2026 - 2:23 by Viska
  • Thanks Now Microsoft could document them as well, and put...19. August 2026 - 16:26 by Andreas Wolter
  • List of Action_IDs for Filter https://sqlquantumleap.com/reference/server-audit-filter-values-for-action_id/ Great...18. August 2026 - 0:59 by Peter Dünsch

Articles

Analysis Services Auditing Availability Groups Azure Best Practices Certification Columnstore Consolidation Deadlocks & Blocking Encryption Extended Events Get-SqlSafe In-Memory OLTP Indexing Least Privilege PASS Summit Patching Performance Analysis Permissions Privilege Escalation Reporting Services Security Principles Spatial Data SQLBits SQL Injection SQLSaturday SQL Server 2012 SQL Server 2014 SQL Server 2016 SQL Server 2022 SQL Server 2025 SQL Trace & Profiler sysadmin & Server Roles Threat Detection Vulnerabilities Workshop & PreCon
© 2026 Andreas WolterContactImprintPrivacy PolicyLinkedInRSS
Link to: Where are the scripts to the session „SQL Attacked/Hacking SQL Server“ ? ;-) Link to: Where are the scripts to the session „SQL Attacked/Hacking SQL Server“ ? ;-) Where are the scripts to the session „SQL Attacked/Hacking SQL Server“ ?... Link to: MCSM (Microsoft Certified Solutions Master) Data Platform on SQL Server 2012 Link to: MCSM (Microsoft Certified Solutions Master) Data Platform on SQL Server 2012 MCSM (Microsoft Certified Solutions Master) Data Platform on SQL Server 201...
Scroll to top Scroll to top Scroll to top
Manage Consent
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
  • Manage options
  • Manage services
  • Manage {vendor_count} vendors
  • Read more about these purposes
View preferences
  • {title}
  • {title}
  • {title}