<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Sp_change_users_login on SQL Server Scripts</title><link>https://www.sqlserver70.com/tags/sp_change_users_login/</link><description>Recent content in Sp_change_users_login 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/tags/sp_change_users_login/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;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;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></channel></rss>