<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>SQL Table Ownership Changes, Quick and Easy</title><link>http://weblogs.asp.net/owscott/archive/2004/01/30/SQL-Table-Ownership-Changes_2C00_-Quick-and-Easy.aspx</link><description>A common task I run into is changing the ownership on a database table or stored procedure in SQL Server. There are times when the owner is set incorrectly or differently what what I would like. For example, if a table is created using &amp;#39;CREATE TABLE</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>re: SQL Table Ownership Changes, Quick and Easy</title><link>http://weblogs.asp.net/owscott/archive/2004/01/30/SQL-Table-Ownership-Changes_2C00_-Quick-and-Easy.aspx#2844061</link><pubDate>Sun, 17 Jun 2007 09:34:39 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:2844061</guid><dc:creator>Papayjl</dc:creator><author>Papayjl</author><description>&lt;p&gt;&amp;lt;a href= &lt;a rel="nofollow" target="_new" href="http://monophthongizesardin.pochtamt.ru"&gt;monophthongizesardin.pochtamt.ru&lt;/a&gt; &amp;gt;lynn doyle&amp;lt;/a&amp;gt; &amp;lt;a href= &lt;a rel="nofollow" target="_new" href="http://accommodatingdo.pochtamt.ru"&gt;accommodatingdo.pochtamt.ru&lt;/a&gt; &amp;gt;wgn&amp;lt;/a&amp;gt; &amp;lt;a href= &lt;a rel="nofollow" target="_new" href="http://lyonsredint.pochtamt.ru"&gt;http://lyonsredint.pochtamt.ru&lt;/a&gt; &amp;gt;restaurants in whittier 90601&amp;lt;/a&amp;gt; &amp;lt;a href= &lt;a rel="nofollow" target="_new" href="http://bizarredirectre.pochtamt.ru"&gt;bizarredirectre.pochtamt.ru&lt;/a&gt; &amp;gt;spa at the avenue baltimore&amp;lt;/a&amp;gt; &amp;lt;a href= &lt;a rel="nofollow" target="_new" href="http://hemlocktriangular.pochtamt.ru"&gt;hemlocktriangular.pochtamt.ru&lt;/a&gt; &amp;gt;piliceimpounds&amp;lt;/a&amp;gt; &amp;lt;a href= &lt;a rel="nofollow" target="_new" href="http://parameterp.pochtamt.ru"&gt;http://parameterp.pochtamt.ru&lt;/a&gt; &amp;gt;nude beaches new york&amp;lt;/a&amp;gt; &amp;lt;a href= &lt;a rel="nofollow" target="_new" href="http://theat.pochtamt.ru"&gt;http://theat.pochtamt.ru&lt;/a&gt; &amp;gt;refurbished canon pixma&amp;lt;/a&amp;gt; &amp;lt;a href= &lt;a rel="nofollow" target="_new" href="http://publishinggentleness.pochtamt.ru"&gt;publishinggentleness.pochtamt.ru&lt;/a&gt; &amp;gt;wedding on video&amp;lt;/a&amp;gt; &amp;lt;a href= &lt;a rel="nofollow" target="_new" href="http://corgipondage.pochtamt.ru"&gt;corgipondage.pochtamt.ru&lt;/a&gt; &amp;gt;catholic jewelry&amp;lt;/a&amp;gt; &amp;lt;a href= &lt;a rel="nofollow" target="_new" href="http://aquiferoussupport.pochtamt.ru"&gt;aquiferoussupport.pochtamt.ru&lt;/a&gt; &amp;gt;shopzilla&amp;lt;/a&amp;gt;&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=2844061" width="1" height="1"&gt;</description></item><item><title>re: SQL Table Ownership Changes, Quick and Easy</title><link>http://weblogs.asp.net/owscott/archive/2004/01/30/SQL-Table-Ownership-Changes_2C00_-Quick-and-Easy.aspx#2732967</link><pubDate>Tue, 05 Jun 2007 14:16:09 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:2732967</guid><dc:creator>Bill S</dc:creator><author>Bill S</author><description>&lt;p&gt;Now that is a slick script. &amp;nbsp;Thanks much!&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=2732967" width="1" height="1"&gt;</description></item><item><title>re: SQL Table Ownership Changes, Quick and Easy</title><link>http://weblogs.asp.net/owscott/archive/2004/01/30/SQL-Table-Ownership-Changes_2C00_-Quick-and-Easy.aspx#2182504</link><pubDate>Thu, 05 Apr 2007 14:01:03 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:2182504</guid><dc:creator>Shridhar</dc:creator><author>Shridhar</author><description>&lt;p&gt;Saved my day yesterday! &amp;nbsp;I had to tweak it a bit to work for views ... no problems.&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=2182504" width="1" height="1"&gt;</description></item><item><title>re: SQL Table Ownership Changes, Quick and Easy</title><link>http://weblogs.asp.net/owscott/archive/2004/01/30/SQL-Table-Ownership-Changes_2C00_-Quick-and-Easy.aspx#1988696</link><pubDate>Sat, 10 Mar 2007 10:36:04 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:1988696</guid><dc:creator>AZ</dc:creator><author>AZ</author><description>&lt;p&gt;Great! Works just like a charm!&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=1988696" width="1" height="1"&gt;</description></item><item><title>re: SQL Table Ownership Changes, Quick and Easy</title><link>http://weblogs.asp.net/owscott/archive/2004/01/30/SQL-Table-Ownership-Changes_2C00_-Quick-and-Easy.aspx#1521147</link><pubDate>Fri, 02 Feb 2007 11:55:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:1521147</guid><dc:creator>soumya</dc:creator><author>soumya</author><description>&lt;p&gt;great article. thanks!&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=1521147" width="1" height="1"&gt;</description></item><item><title>re: SQL Table Ownership Changes, Quick and Easy</title><link>http://weblogs.asp.net/owscott/archive/2004/01/30/SQL-Table-Ownership-Changes_2C00_-Quick-and-Easy.aspx#1351960</link><pubDate>Tue, 02 Jan 2007 20:52:22 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:1351960</guid><dc:creator>Rick T</dc:creator><author>Rick T</author><description>&lt;p&gt;Thanks for the tip on the system sproc Scott. &amp;nbsp;Most helpful!&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=1351960" width="1" height="1"&gt;</description></item><item><title>re: SQL Table Ownership Changes, Quick and Easy</title><link>http://weblogs.asp.net/owscott/archive/2004/01/30/SQL-Table-Ownership-Changes_2C00_-Quick-and-Easy.aspx#1083022</link><pubDate>Thu, 30 Nov 2006 11:53:03 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:1083022</guid><dc:creator>Darran</dc:creator><author>Darran</author><description>&lt;p&gt;I have adjusted the code slightly for a SQL 2005 version. I'm not a SQL expert, so I'd welcome comments if this code will work as I'd expect.&lt;/p&gt;
&lt;p&gt;DECLARE @old sysname, @sql varchar(1000)&lt;/p&gt;
&lt;p&gt;SELECT&lt;/p&gt;
&lt;p&gt; &amp;nbsp;@old = 'oldOwner_CHANGE_THIS'&lt;/p&gt;
&lt;p&gt; &amp;nbsp;, @sql = '&lt;/p&gt;
&lt;p&gt; &amp;nbsp;IF EXISTS (SELECT NULL FROM INFORMATION_SCHEMA.TABLES&lt;/p&gt;
&lt;p&gt; &amp;nbsp;WHERE&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;QUOTENAME(TABLE_SCHEMA)+''.''+QUOTENAME(TABLE_NAME) = ''?''&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;AND TABLE_SCHEMA = ''' + @old + '''&lt;/p&gt;
&lt;p&gt; &amp;nbsp;)&lt;/p&gt;
&lt;p&gt; &amp;nbsp;ALTER SCHEMA dbo TRANSFER ?'&lt;/p&gt;
&lt;p&gt;EXECUTE sp_MSforeachtable @sql&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=1083022" width="1" height="1"&gt;</description></item><item><title>re: SQL Table Ownership Changes, Quick and Easy</title><link>http://weblogs.asp.net/owscott/archive/2004/01/30/SQL-Table-Ownership-Changes_2C00_-Quick-and-Easy.aspx#207400</link><pubDate>Tue, 03 Aug 2004 22:56:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:207400</guid><dc:creator>Scott Forsyth</dc:creator><author>Scott Forsyth</author><description>Hesky.  I can't answer that right off.  You can do it from Enterprise Manager by starting the process of detaching a database and killing all sessions.  But from SQL directly, I would have to look it up. I don't know right off.&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=207400" width="1" height="1"&gt;</description></item><item><title>re: SQL Table Ownership Changes, Quick and Easy</title><link>http://weblogs.asp.net/owscott/archive/2004/01/30/SQL-Table-Ownership-Changes_2C00_-Quick-and-Easy.aspx#197282</link><pubDate>Mon, 26 Jul 2004 18:36:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:197282</guid><dc:creator>Hesky</dc:creator><author>Hesky</author><description>Could we also use this script if users are using the table?? SO what i want i to change the ownership when also the users are using this table in the application. Is there a possiblity drop all users which are connecting to these table??&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=197282" width="1" height="1"&gt;</description></item><item><title>re: SQL Table Ownership Changes, Quick and Easy</title><link>http://weblogs.asp.net/owscott/archive/2004/01/30/SQL-Table-Ownership-Changes_2C00_-Quick-and-Easy.aspx#170157</link><pubDate>Wed, 30 Jun 2004 20:02:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:170157</guid><dc:creator>Scott Forsyth</dc:creator><author>Scott Forsyth</author><description>Kenneth, thanks for the post.  I'll get the script for stored procedures and add it here.  I'll remove your post then too.  David Penton will have something for this, I'm sure.  &lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=170157" width="1" height="1"&gt;</description></item></channel></rss>