User Tools

Site Tools


programming:sql:mssql

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
programming:sql:mssql [2026/01/27 09:56] – Added the subheadline "Show database owner" with TSQL and source links. basprogramming:sql:mssql [2026/01/27 10:00] (current) – Added exeample to limit database to those of a specific user to [Show database owner]. bas
Line 329: Line 329:
 SELECT name, owner_sid, (SELECT SUSER_SNAME(owner_sid)) AS owner_name FROM sys.databases SELECT name, owner_sid, (SELECT SUSER_SNAME(owner_sid)) AS owner_name FROM sys.databases
 WHERE name LIKE 'PREFIX_%' WHERE name LIKE 'PREFIX_%'
 +ORDER BY name
 +</code>
 +
 +Show only databases whose name starts with "PREFIX_" AND owner is "AD\sa_Owner", show the name, owner_sid, and owner_name:
 +
 +<code tsql>
 +SELECT name, owner_sid, (SELECT SUSER_SNAME(owner_sid)) AS owner_name FROM sys.databases
 +WHERE name LIKE 'PREFIX_%'
 +AND (SELECT SUSER_SNAME(owner_sid)) = 'AD\sa_Owner'
 ORDER BY name ORDER BY name
 </code> </code>
programming/sql/mssql.txt · Last modified: by bas

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki