<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>SQL Server Security on SQL Server Scripts</title><link>https://www.sqlserver70.com/series/sql-server-security/</link><description>Recent content in SQL Server Security on SQL Server Scripts</description><generator>Hugo -- gohugo.io</generator><language>en</language><copyright>SQLServer70.com</copyright><lastBuildDate>Fri, 17 Apr 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://www.sqlserver70.com/series/sql-server-security/index.xml" rel="self" type="application/rss+xml"/><item><title>SQL Server Find Orphan Users Script</title><link>https://www.sqlserver70.com/post/sql-server-find-orphan-users-script/</link><pubDate>Fri, 17 Apr 2026 00:00:00 +0000</pubDate><guid>https://www.sqlserver70.com/post/sql-server-find-orphan-users-script/</guid><description>
&lt;p&gt;Orphaned database users are a common problem after database restores, server migrations, or login deletions. A database user becomes orphaned when its SID does not match any server-level login SID. This script queries &lt;code&gt;sys.database_principals&lt;/code&gt; and &lt;code&gt;sys.server_principals&lt;/code&gt; to find every orphaned user in a database, and shows how to fix them.&lt;/p&gt;
&lt;h2 id="purpose-and-overview"&gt;Purpose and Overview&lt;/h2&gt;
&lt;script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1012089347386563"
crossorigin="anonymous"&gt;&lt;/script&gt;
&lt;ins class="adsbygoogle"
style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-pub-1012089347386563"
data-ad-slot="8593449130"&gt;&lt;/ins&gt;
&lt;script&gt;
(adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;p&gt;When you restore a database to a new server, or when a Windows account or SQL login is dropped at the server level, the corresponding database user record remains in the database. That user is now orphaned — it exists in &lt;code&gt;sys.database_principals&lt;/code&gt; but has no matching entry in &lt;code&gt;sys.server_principals&lt;/code&gt; by SID.&lt;/p&gt;</description></item><item><title>SQL Server User Permissions and Role Memberships</title><link>https://www.sqlserver70.com/post/sql-server-list-all-user-permissions-role-memberships/</link><pubDate>Fri, 10 Apr 2026 00:00:00 +0000</pubDate><guid>https://www.sqlserver70.com/post/sql-server-list-all-user-permissions-role-memberships/</guid><description>
&lt;h2 id="audit-sql-server-database-user-permissions-and-role-memberships"&gt;Audit SQL Server Database User Permissions and Role Memberships&lt;/h2&gt;
&lt;p&gt;This script queries the SQL Server system catalog to produce a complete audit of database-level permissions, covering direct object grants to users, permissions inherited through database roles, and permissions granted to the public role — all in a single result set.&lt;/p&gt;
&lt;script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1012089347386563"
crossorigin="anonymous"&gt;&lt;/script&gt;
&lt;ins class="adsbygoogle"
style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-pub-1012089347386563"
data-ad-slot="8593449130"&gt;&lt;/ins&gt;
&lt;script&gt;
(adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;h2 id="purpose-and-overview"&gt;Purpose and Overview&lt;/h2&gt;
&lt;p&gt;Understanding who has access to what in a SQL Server database is a fundamental security and compliance requirement. Permissions in SQL Server are layered: a user may have rights granted directly, through membership in one or more database roles, or through the public role that every user belongs to by default. Auditing all three layers individually is time-consuming. This script, from the DBA-Scripts collection by Bulent Gucuk, uses three UNION-connected queries against the system catalog views to produce one flat result set covering every permission pathway for every user. Security teams can use the output for access reviews, compliance audits, and troubleshooting unexpected permission grants or denials.&lt;/p&gt;</description></item><item><title>SQL Server Object Permissions: Generate GRANT Statements</title><link>https://www.sqlserver70.com/post/sql-server-object-level-permissions-script-generate-grant-statements-for-database-security/</link><pubDate>Fri, 08 Aug 2025 00:00:00 +0000</pubDate><guid>https://www.sqlserver70.com/post/sql-server-object-level-permissions-script-generate-grant-statements-for-database-security/</guid><description>
&lt;h2 id="sql-server-object-level-permissions-script-generate-grant-statements-for-database-security"&gt;SQL Server Object-Level Permissions Script: Generate GRANT Statements for Database Security&lt;/h2&gt;
&lt;p&gt;Database security is a critical aspect of SQL Server administration, and managing permissions at the object level can be time-consuming when done manually. This SQL Server script automates the process of generating GRANT statements for all database objects, making it easier for database administrators to apply consistent permissions across their database schema.&lt;/p&gt;
&lt;h2 id="purpose-of-the-script"&gt;Purpose of the Script&lt;/h2&gt;
&lt;p&gt;This SQL Server script is designed to automatically generate GRANT permission statements for all user tables and stored procedures in a database. Instead of manually writing individual GRANT statements for each object, this script queries the system catalog to dynamically create the necessary permission commands for a specific database role called &lt;code&gt;SelectInsertUpdateDeleteExecSP&lt;/code&gt;.
&lt;script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1012089347386563"
crossorigin="anonymous"&gt;&lt;/script&gt;
&lt;ins class="adsbygoogle"
style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-pub-1012089347386563"
data-ad-slot="8593449130"&gt;&lt;/ins&gt;
&lt;script&gt;
(adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/p&gt;</description></item></channel></rss>