Managing database ownership in SQL Server 2019 is a critical responsibility for database administrators who need to maintain security, audit access, and troubleshoot permission issues across enterprise environments. If you are looking for a reliable way to run SQL Server 2019 get all databases and owners group name, understanding the relationship between system catalog views, security principals, and Windows groups is essential. This guide walks you through the most effective T-SQL techniques to list every database on an instance, identify its owner, and resolve the associated Windows group or login name so you can maintain accurate ownership records and enforce least-privilege access.
Why Database Ownership Matters in SQL Server 2019
Every database in SQL Server 2019 has an owner, which is the security principal that initially created the database or was assigned ownership through an explicit authorization change. Also, the database owner plays a significant role in the ownership chain, which determines how SQL Server evaluates permissions when accessing objects such as tables, views, and stored procedures. When the database owner is a Windows group rather than an individual SQL login, managing access becomes more centralized because membership in that group is controlled at the Active Directory level Most people skip this — try not to..
Quick Overview of Key System Views
| View | What It Provides | Typical Join |
|---|---|---|
| **`sys. | ||
sys.That said, sql_logins (in master) |
SQL Server logins, including Windows‑authenticated ones. On top of that, server_principals** (in master`) |
Server‑level principals (logins, Windows users/groups, and SQL users). |
sys.Now, dm_db_database_auth (SQL Server 2022+) |
Returns the effective owner for each database, already resolved to a name and authentication type. | |
**sys.database_principals on principal_id = owner_sid. Consider this: use this when you need the full server‑principal taxonomy. So |
Join on sid = owner_sid. And useful for a one‑liner if you’re on the latest version. databases` is the database owner. |
|
**sys.Columns: name, principal_id, sid, type, type_desc. In practice, sql_logins. Still, databases** (in master`) |
List of all user‑visible databases on the instance, their owner_sid, database_id, and name. |
No join required. |
These views are the foundation of any script that needs to “run SQL Server 2019 get all databases and owners group name”.
Method 1 – Classic T‑SQL Using sys.databases and sys.database_principals
/* List every database, its owner SID, and the owner’s name */
SELECT
d.name AS DatabaseName,
d.owner_sid AS OwnerSID,
dp.name AS OwnerName,
dp.type_desc AS OwnerType, -- e.g., 'SQL_USER', 'WINDOWS_GROUP'
dp.authentication_type_desc AS AuthSource -- 'Windows', 'SQL Server'
FROM master.sys.databases AS d
JOIN [$(DatabaseName)].[sys].database_principals AS dp
ON dp.principal_id = d.owner_sid
WHERE d.state_desc = 'ONLINE' -- optional: ignore offline DBs
ORDER BY d.name;
Why this works
sys.databaseslives in the master database and contains theowner_sidfor each database.sys.database_principalslives inside each database, but you can query it from any context because theprincipal_idis a global identifier. The row whoseprincipal_idmatches theowner_sidis the owner.- The
type_desccolumn tells you whether the owner is a SQL user (SQL_USER) or a Windows principal (WINDOWS_USER/WINDOWS_GROUP).authentication_type_descfurther refines the source (Windows vs. SQL Server).
Result snapshot (typical output)
| DatabaseName | OwnerSID | OwnerName | OwnerType | AuthSource |
|---|---|---|---|---|
| AdventureWorks | 0x0109000000000010000000000000000F010000003E000000 |
DOMAIN\DB-Owners |
WINDOWS_GROUP |
Windows |
| TempDB | 0x0109000000000010000000000000000F010000003E000000 |
sa |
SQL_USER |
SQL Server |
| ReportServer | 0x0109000000000010000000000000000F010000003E000000 |
DOMAIN\ReportsAdmin |
WINDOWS_GROUP |
Windows |
Method 2 – Resolve the Owner to a Login/Group Name via sys.sql_logins
When you need the login that the owner maps to (especially for Windows groups), join sys.sys.sys.Also, databases to master. This leads to sql_logins (or master. In real terms, server_principals). This step is crucial for “get all databases and owners group name”.
/* Full resolution: database → owner login → Windows group name */
SELECT
d.name AS DatabaseName,
dp.name AS OwnerName,
sl.name AS LoginName, -- the login/group name
sl.type_desc AS LoginType, -- 'WINDOWS_GROUP', 'SQL_USER', etc.
sl.authentication_type_desc AS LoginAuthSource,
d.owner_sid AS OwnerSID
FROM master.sys.databases AS d
JOIN master.sys.database_principals AS dp
ON dp.principal_id = d.owner_sid
JOIN master.sys.sql_log