<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>schema - Techyaz.com</title>
	<atom:link href="https://techyaz.com/tag/schema/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>Tips, Tutorials and How-to Topics</description>
	<lastBuildDate>Sun, 06 May 2018 11:31:46 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.1</generator>

<image>
	<url>https://techyaz.com/wp-content/uploads/2017/11/cropped-Site-icon-150x150.png</url>
	<title>schema - Techyaz.com</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Fix SQL Server Error 15138: Dropping User that owned Schema &#038; Error 3729: Schema that referenced to the object</title>
		<link>https://techyaz.com/sql-server/troubleshooting/fix-error-15138-error-3729/</link>
					<comments>https://techyaz.com/sql-server/troubleshooting/fix-error-15138-error-3729/#comments</comments>
		
		<dc:creator><![CDATA[Manvendra Deo Singh]]></dc:creator>
		<pubDate>Fri, 04 Aug 2017 12:02:15 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Troubleshooting]]></category>
		<category><![CDATA[Drop Login Failed]]></category>
		<category><![CDATA[HowTO]]></category>
		<category><![CDATA[schema]]></category>
		<category><![CDATA[SQL_Error_Code]]></category>
		<category><![CDATA[user]]></category>
		<guid isPermaLink="false">http://techyaz.com/?p=391</guid>

					<description><![CDATA[<p>Here we will learn how to fix Microsoft SQL Server error 15138 &#38; error 3729 that we receive while dropping a database user and a schema in SQL Server.  Let us check the details to fix this issue one after&#46;&#46;&#46;</p>
<p>The post <a href="https://techyaz.com/sql-server/troubleshooting/fix-error-15138-error-3729/">Fix SQL Server Error 15138: Dropping User that owned Schema &#038; Error 3729: Schema that referenced to the object</a> appeared first on <a href="https://techyaz.com">Techyaz.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Here we will learn how to fix Microsoft SQL Server error 15138 &amp; error 3729 that we receive while dropping a database user and a schema in SQL Server.  Let us check the details to fix this issue one after another.</p>
<h3><span style="color: #800000;"><strong>Microsoft SQL Server Error 15138</strong></span></h3>
<p>I have discussed similar type of issue in my last tip, where a server level login was owner of some databases which causes to <a href="https://techyaz.com/sql-server/troubleshooting/fix-the-error-15174/" target="_blank" rel="noopener">fail the login removal and throws error 15174</a>. We changed the ownership and then tried to drop that login and it was successful.</p>
<p>Microsoft SQL Server Error 15138 which i am discussing in this tip is also similar kind of error. Here, user has owned some schemas at database level. We will do the same thing, we will change the owner of identified schema and drop the user.</p>
<p>The details of SQL Server error 15138 is given below.</p>
<div class="codediv"><span class="kwrd" style="color: red;">Drop failed for User &#8216;xyz&#8217;.<br />
The database principal owns a schema in the database, and cannot be dropped. (Microsoft SQL Server, Error:15138)</span></div>
<p><img fetchpriority="high" decoding="async" class="aligncenter size-full wp-image-392" src="http://techyaz.com/wp-content/uploads/2017/08/error-15138.png" alt="error 15138" width="618" height="268" srcset="https://techyaz.com/wp-content/uploads/2017/08/error-15138.png 618w, https://techyaz.com/wp-content/uploads/2017/08/error-15138-300x130.png 300w" sizes="(max-width: 618px) 100vw, 618px" /></p>
<p>As error clearly says that a schema is owned by this user in the database so let us check the schema that is owned by this user. Please follow the below process to check the owned schema for an user in the database.</p>
<ul>
<li>Connect to SQL Server Instance in SSMS.</li>
<li>Expand the database folder followed by the actual database name in which your user exists or created.</li>
<li>Expand Security folder inside your target database followed by the Users folder and double click on the target user which you want to drop.</li>
<li>You can see a section named &#8220;Owned Schemas. Here you can see the schemas that are owned by this user.</li>
</ul>
<p>If you find any schema that is owned by this user in above steps, you need to change the owner from this user to some other user or you can change it to dbo as well. See the below screenshot of the owned schema for a user.</p>
<p><img decoding="async" class="aligncenter size-full wp-image-393" src="http://techyaz.com/wp-content/uploads/2017/08/owned-schema.jpg" alt="owned schema" width="474" height="372" srcset="https://techyaz.com/wp-content/uploads/2017/08/owned-schema.jpg 474w, https://techyaz.com/wp-content/uploads/2017/08/owned-schema-300x235.jpg 300w" sizes="(max-width: 474px) 100vw, 474px" /></p>
<h3><span style="color: #800000;"><strong>Solution</strong></span></h3>
<p>Now we have identified the schema which is owned by this user. Our Next step is to change is owner of the identified schema and then drop the login.</p>
<pre class="brush: sql; title: ; notranslate" title=""><strong><span class="kwrd" style="color: green;"> --Change DBName with your database name and Schema_Name with your schema name which is owned by this user.</span>
<span class="kwrd" style="color: blue;">USE [DBName] </span>
<span class="kwrd" style="color: blue;">G0 </span>
<span class="kwrd" style="color: blue;">Alter Authorization ON Schema::[SCHEMA_NAME] TO [dbo] </span>
<span class="kwrd" style="color: blue;">Go</span></strong></pre>
<p>Once above command will execute, next step is to drop the user again. Run below command to drop the user.</p>
<pre class="brush: sql; title: ; notranslate" title=""><strong><span class="kwrd" style="color: green;">--Change DBName with your database name where user exists and USERNAME with user name which you want to drop.</span>
<span class="kwrd" style="color: blue;">USE [DBName] </span>
<span class="kwrd" style="color: blue;">Go </span>
<span class="kwrd" style="color: blue;">DROP USER USERNAME </span>
<span class="kwrd" style="color: blue;">Go</span></strong></pre>
<p>This time it will work and user will drop from the database. You can also delete this user from SSMS by right click on the user and choose the delete option. SSMS way is given below:</p>
<ul>
<li>Connect to target SQL Server Instance.</li>
<li>Expand Database folder in which user exists.</li>
<li>Expand the Security folder and then Users folder to get the target user name.</li>
<li>Right click and choose delete on the identified user which needs to be deleted.</li>
<li>Click on Ok button of the user deletion window.</li>
</ul>
<p>There are many reasons which causes to fail the user or login deletion. You can find many errors and their solutions in given links. Learn to fix:</p>
<ul>
<li><strong><a href="https://techyaz.com/sql-server/troubleshooting/fix-the-error-15174/" target="_blank" rel="noopener">Error Code 15174: Login Owns one or more databases(s). Change the owner of database(s) before dropping the login.</a></strong></li>
<li><strong><a href="https://techyaz.com/sql-server/troubleshooting/fix-error-15173/" target="_blank" rel="noopener">Error Code 15173: Revoke the permission(s) before dropping the login.</a></strong></li>
</ul>
<h3><span style="color: #800000;"><strong>Microsoft SQL Server Error 3729</strong></span></h3>
<p>We have seen how to drop an user who was owner of a schema in above section. Now we will understand how to drop a schema that is referenced by an object. If you try to run DROP Schema statement and that particular schema is referenced to some object you will get below error. The details of SQL Server error 3729 is given below.</p>
<div class="codediv"><span class="kwrd" style="color: red;">Drop failed for Schema &#8216;abc&#8217;.<br />
Cannot drop schema &#8216;abc&#8217; because it is being referenced by object &#8216;Locations&#8217;. (Microsoft SQL Server, Error 3729)</span></div>
<p>In order to fix this issue, we will change the schema of table &#8220;Locations&#8221; to remove the reference. We will use <strong><span style="color: #800000;">sp_changeobjectowner</span></strong> system stored procedure to change schema from abc to dbo. Run below command to change the schema of the table &#8220;Locations&#8221; from abc to dbo.</p>
<pre class="brush: sql; title: ; notranslate" title=""><strong><span class="kwrd" style="color: green;">--Change DBName with your database name where user/schema/table exists
--Change the abc to your schema name.</span><span class="kwrd" style="color: blue;">
USE DBName
GO
sp_changeobjectowner 'abc.Locations','dbo'
</span></strong></pre>
<p>Now go ahead and drop the schema post executing above command. This time it will drop without an error.</p>
<pre class="brush: sql; title: ; notranslate" title=""><strong><span class="kwrd" style="color: green;">--Change DBName with your database name where user/schema/table exists
--Change the abc to your schema name which you want to delete.</span><span class="kwrd" style="color: blue;">
USE [DBName]
GO
DROP SCHEMA [abc]
GO
</span></strong></pre>
<p>You can also drop the same using SSMS as well. Go to schema folder inside the security folder of your database. Right click on identified schema and choose delete option.  it will delete your schema.</p>
<p>Learn to fix below errors as well:</p>
<ul>
<li><strong><a href="https://techyaz.com/sql-server/troubleshooting/fix-the-error-15174/" target="_blank" rel="noopener">Error Code 15174: Login Owns one or more databases(s). Change the owner of database(s) before dropping the login.</a></strong></li>
<li><strong><a href="https://techyaz.com/sql-server/troubleshooting/fix-error-15173/" target="_blank" rel="noopener">Error Code 15173: Revoke the permission(s) before dropping the login.</a></strong></li>
</ul>
<p>I hope you like this article. Please follow us on our <a href="https://www.facebook.com/Techyaz/">facebook page</a> and on <a href="htts://twitter.com/Tech_yaz">Twitter </a>handle to get latest updates.</p>
<p>The post <a href="https://techyaz.com/sql-server/troubleshooting/fix-error-15138-error-3729/">Fix SQL Server Error 15138: Dropping User that owned Schema &#038; Error 3729: Schema that referenced to the object</a> appeared first on <a href="https://techyaz.com">Techyaz.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://techyaz.com/sql-server/troubleshooting/fix-error-15138-error-3729/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
	</channel>
</rss>
