<?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>Allen Kinsel - SQL DBA &#187; Bits N Bytes</title>
	<atom:link href="http://www.allenkinsel.com/Topics/sql-server/bits-n-bytes/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.allenkinsel.com</link>
	<description>SQL Server, PASS, and other data mishaps</description>
	<lastBuildDate>Tue, 08 May 2012 13:09:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
<image>
  <link>http://www.allenkinsel.com</link>
  <url>http://www.allenkinsel.com/favicon.ico</url>
  <title>Allen Kinsel - SQL DBA</title>
</image>
		<item>
		<title>Database Automagic</title>
		<link>http://www.allenkinsel.com/archive/2011/02/database-automagic/</link>
		<comments>http://www.allenkinsel.com/archive/2011/02/database-automagic/#comments</comments>
		<pubDate>Tue, 08 Feb 2011 17:11:30 +0000</pubDate>
		<dc:creator>Allen Kinsel</dc:creator>
				<category><![CDATA[Bits N Bytes]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Syndicated]]></category>
		<category><![CDATA[TSQLTuesday]]></category>
		<category><![CDATA[BitsNBytes]]></category>
		<category><![CDATA[tsql2sday]]></category>

		<guid isPermaLink="false">http://www.allenkinsel.com/?p=737</guid>
		<description><![CDATA[This months TSQL Tuesday is hosted by a good friend Pat right over at  SQL Asylum
For this months entry I decided to keep it short and sweet, following in my Bits N Bytes theme.
The Meta Script
In the true sense of the word automation, this really doesn&#8217;t fit but, in the terms of quickly getting something]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft" title="tsql2sday" src="http://sqlasylum.files.wordpress.com/2011/01/tsql2sday.jpg" alt="" width="150" height="150" />This months TSQL Tuesday is hosted by a good friend Pat right over at <a href="http://sqlasylum.wordpress.com/2011/02/01/invitation-to-t-sql-tuesday-15-automation-in-sql-server/"> SQL Asylum</a></p>
<p>For this months entry I decided to keep it short and sweet, following in my Bits N Bytes theme.</p>
<h3>The Meta Script</h3>
<p>In the true sense of the word automation, this really doesn&#8217;t fit but, in the terms of quickly getting something done that would otherwise be a mundane repetitive task, this can save a world of time.</p>
<p>Lets say we have a list of objects in the Sales Schema and we have a request to grant Select and Insert access to a user for those objects.  There are two approaches, 1 is to grant select and insert to the actual schema like this</p>
<p><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;">GRANT</span></span></span><span style="color: #0000ff; font-size: x-small;"> </span></span><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;">SELECT, INSERT</span></span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;">ON</span></span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;">SCHEMA</span></span><span style="color: #808080; font-size: x-small;"><span style="color: #808080; font-size: x-small;">::</span></span><span style="font-size: x-small;">Sales </span><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;">TO</span></span><span style="font-size: x-small;"> BusinessUser</span><span style="font-size: x-small;"> </span></p>
<p>However you might decide that you only want to grant direct SELECT and INSERT on the tables that exist in the DBO Schema today not those tables which may be created in the future (auditors love to make us do this)</p>
<p>A simple way to automate granting these rights is by writing a script that writes a script like so</p>
<div><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;">SELECT</span></span></div>
<div><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;"><span style="color: #ff0000; font-size: x-small;"><span style="color: #ff0000; font-size: x-small;">&#8216;GRANT SELECT, INSERT ON &#8216;</span></span><span style="font-size: x-small;"> </span><span style="color: #808080; font-size: x-small;"><span style="color: #808080; font-size: x-small;">+</span></span><span style="font-size: x-small;"> sch</span><span style="color: #808080; font-size: x-small;"><span style="color: #808080; font-size: x-small;">.</span></span><span style="font-size: x-small;">name </span><span style="color: #808080; font-size: x-small;"><span style="color: #808080; font-size: x-small;">+</span></span><span style="font-size: x-small;"> </span><span style="color: #ff0000; font-size: x-small;"><span style="color: #ff0000; font-size: x-small;">&#8216;.&#8217;</span></span><span style="font-size: x-small;"> </span><span style="color: #808080; font-size: x-small;"><span style="color: #808080; font-size: x-small;">+</span></span><span style="font-size: x-small;"> obj</span><span style="color: #808080; font-size: x-small;"><span style="color: #808080; font-size: x-small;">.</span></span><span style="font-size: x-small;">name </span><span style="color: #808080; font-size: x-small;"><span style="color: #808080; font-size: x-small;">+</span></span><span style="font-size: x-small;"> </span><span style="color: #ff0000; font-size: x-small;"><span style="color: #ff0000; font-size: x-small;">&#8216; TO BusinessUser&#8217;</span></span></span></span></div>
<div><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;"> </span></span><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;"><span style="font-size: x-small;"><span style="font-size: x-small;"><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;">  FROM</span></span><span style="font-size: x-small;"> </span><span style="color: #008000; font-size: x-small;"><span style="color: #008000; font-size: x-small;">sys</span></span><span style="color: #808080; font-size: x-small;"><span style="color: #808080; font-size: x-small;">.</span></span><span style="color: #008000; font-size: x-small;"><span style="color: #008000; font-size: x-small;">all_objects</span></span><span style="font-size: x-small;"> obj </span></span></span></span></span><span style="color: #808080; font-size: x-small;"><span style="color: #808080; font-size: x-small;">JOIN</span></span><span style="font-size: x-small;"> </span><span style="color: #008000; font-size: x-small;"><span style="color: #008000; font-size: x-small;">sys</span></span><span style="color: #808080; font-size: x-small;"><span style="color: #808080; font-size: x-small;">.</span></span><span style="color: #008000; font-size: x-small;"><span style="color: #008000; font-size: x-small;">schemas</span></span><span style="font-size: x-small;"> sch</span></div>
<div><span style="font-size: x-small;"><span style="font-size: x-small;"> </span></span></div>
<p><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;">    ON</span></span><span style="font-size: x-small;"> obj</span><span style="color: #808080; font-size: x-small;"><span style="color: #808080; font-size: x-small;">.</span></span><span style="color: #ff00ff; font-size: x-small;"><span style="color: #ff00ff; font-size: x-small;">schema_id</span></span><span style="font-size: x-small;"> </span><span style="color: #808080; font-size: x-small;"><span style="color: #808080; font-size: x-small;">=</span></span><span style="font-size: x-small;"> sch</span><span style="color: #808080; font-size: x-small;"><span style="color: #808080; font-size: x-small;">.</span></span><span style="color: #ff00ff; font-size: x-small;"><span style="color: #ff00ff; font-size: x-small;">schema_id</span></span></p>
<div><span style="font-size: x-small;"><span style="font-size: x-small;"> </span></span><span style="font-size: x-small;"><span style="font-size: x-small;"> </span></span><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;">WHERE</span></span><span style="font-size: x-small;"> sch</span><span style="color: #808080; font-size: x-small;"><span style="color: #808080; font-size: x-small;">.</span></span><span style="font-size: x-small;">name </span><span style="color: #808080; font-size: x-small;"><span style="color: #808080; font-size: x-small;">=</span></span><span style="font-size: x-small;"> </span><span style="color: #ff0000; font-size: x-small;"><span style="color: #ff0000; font-size: x-small;">&#8216;Sales&#8217;</span></span><br />
<span style="color: #808080; font-size: x-small;"><span style="color: #808080; font-size: x-small;">  and</span></span><span style="font-size: x-small;"> obj</span><span style="color: #808080; font-size: x-small;"><span style="color: #808080; font-size: x-small;">.</span></span><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;">type</span></span><span style="font-size: x-small;"> </span><span style="color: #808080; font-size: x-small;"><span style="color: #808080; font-size: x-small;">=</span></span><span style="font-size: x-small;"> </span><span style="color: #ff0000; font-size: x-small;"><span style="color: #ff0000; font-size: x-small;">&#8216;U&#8217;</span></span></div>
<p><br class="blank" /><br />
This should give you a result set that looks something like the following:</p>
<p><span style="color: #0000ff;">GRANT SELECT, INSERT ON</span> Sales.People <span style="color: #0000ff;">TO</span> BusinessUser<br />
<span style="color: #0000ff;">GRANT SELECT, INSERT ON</span> Sales.Sales <span style="color: #0000ff;">TO</span> BusinessUser</p>
<p>At this point, run the output in a separate command window and viola you&#8217;ve automated that grant of permissions</p>
<p>This may not be true &#8220;automation&#8221; in the sense that Pat was looking for but, perfecting the ability to write scripts that write scripts is a huge timesaver</p>
]]></content:encoded>
			<wfw:commentRss>http://www.allenkinsel.com/archive/2011/02/database-automagic/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Changing the owner of nearly anything in SQL Server</title>
		<link>http://www.allenkinsel.com/archive/2011/01/changing-the-owner-of-nearly-anything/</link>
		<comments>http://www.allenkinsel.com/archive/2011/01/changing-the-owner-of-nearly-anything/#comments</comments>
		<pubDate>Mon, 17 Jan 2011 14:00:00 +0000</pubDate>
		<dc:creator>Allen Kinsel</dc:creator>
				<category><![CDATA[Bits N Bytes]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Syndicated]]></category>
		<category><![CDATA[BitsNBytes]]></category>

		<guid isPermaLink="false">http://www.allenkinsel.com/archive/2011/01/changing-the-owner-of-nearly-anything/</guid>
		<description><![CDATA[The other day we were going through some old scripts and had a huge discussion about changing object ownership in SQL.  Forever the only answers were to recreate the objects or use the stored procedures: sp_changeobjectowner or sp_changedbowner.  Alternatively at times there were those of us who used some other undisclosed hack of system tables]]></description>
			<content:encoded><![CDATA[<p>The other day we were going through some old scripts and had a huge discussion about changing object ownership in SQL.  Forever the only answers were to recreate the objects or use the stored procedures: sp_changeobjectowner or sp_changedbowner.  <span style="text-decoration: line-through;">Alternatively at times there were those of us who used some other undisclosed hack of system tables but, I’ve never done anything like that…</span></p>
<p><span style="text-decoration: line-through;"><br />
</span></p>
<p>Since SQL 2005 Alter Authorization has been the right way to change ownership of nearly anything</p>
<p>This is the most common use of alter authorization but there are <a href="http://msdn.microsoft.com/en-us/library/ms187359.aspx" target="_blank">many more.</a></p>
<p>sp_changeobjectowner would look like this</p>
<pre>sp_changeobjectowner 'Products.Description','AllenK'
</pre>
<p>While the updated syntax would look like this</p>
<pre>ALTER AUTHORIZATION ON OBJECT::[Products].[Description] TO [AllenK]</pre>
<p>What really brought this post about was because I was working with certificates recently and at the time I needed to change who the owner and I just exported/imported &amp; recreated them.  It was easy and what I knew would work.  After looking through the syntax for alter authorization I realized I could &amp; probably should have done it this way.  I guess old habits die hard.</p>
<pre>ALTER AUTHORIZATION ON CERTIFICATE::[MYCERTIFICATE] TO [CERTOWNER]</pre>
<p>Some out there might question why I&#8217;m rehashing syntax changes that happened nearly 5 years ago, The reality is that even in 2011 a lot of the installations of SQL Server I look at are still 2005 and many of the people I run into still use old ways of doing things, this is for you (and me)!</p>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 140px; width: 1px; height: 1px; overflow: hidden;">
<pre>ALTER AUTHORIZATION ON OBJECT::[Products].[Description] TO [AllenK]
</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.allenkinsel.com/archive/2011/01/changing-the-owner-of-nearly-anything/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Something old is something new</title>
		<link>http://www.allenkinsel.com/archive/2011/01/something-old-is-something-new/</link>
		<comments>http://www.allenkinsel.com/archive/2011/01/something-old-is-something-new/#comments</comments>
		<pubDate>Tue, 04 Jan 2011 13:23:39 +0000</pubDate>
		<dc:creator>Allen Kinsel</dc:creator>
				<category><![CDATA[Bits N Bytes]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Syndicated]]></category>
		<category><![CDATA[BitsNBytes]]></category>
		<category><![CDATA[Ideas]]></category>

		<guid isPermaLink="false">http://www.allenkinsel.com/?p=616</guid>
		<description><![CDATA[
For the new year I have decided to try something different with a series of small regular posts.
Dealing with our large team of developers and our DBA team as well, I often run across interesting discussions about small things that are easily overlooked.  Often times these discussions end in a exclamation of &#8220;I knew that!!&#8221;  Of]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.allenkinsel.com/wp-content/uploads/2011/01/340x.jpg"><img class="aligncenter size-medium wp-image-619" title="Old and New" src="http://www.allenkinsel.com/wp-content/uploads/2011/01/340x-300x240.jpg" alt="" width="300" height="240" /></a></p>
<p>For the new year I have decided to try something different with a series of small regular posts.</p>
<p>Dealing with our large team of developers and our DBA team as well, I often run across interesting discussions about small things that are easily overlooked.  Often times these discussions end in a exclamation of &#8220;I knew that!!&#8221;  Of course what really happend is the memory of that specific feature or tidbit has simply been paged out of our memory.  I intend to take these (typicaly) small tidbits of SQL goodness and publish them to hopefully jog your memory as well. </p>
<p>It never hurts to have your memory paged back in occasionally and I hope this helps</p>
]]></content:encoded>
			<wfw:commentRss>http://www.allenkinsel.com/archive/2011/01/something-old-is-something-new/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

