<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>sql_keys</title>
	<atom:link href="http://sqlkeys.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://sqlkeys.wordpress.com</link>
	<description></description>
	<lastBuildDate>Fri, 10 Feb 2012 15:24:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='sqlkeys.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/6d75a162a8cd15a1cdee1b8257f48208?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>sql_keys</title>
		<link>http://sqlkeys.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://sqlkeys.wordpress.com/osd.xml" title="sql_keys" />
	<atom:link rel='hub' href='http://sqlkeys.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Get List of Columns in a Table</title>
		<link>http://sqlkeys.wordpress.com/2012/02/10/get-list-of-columns-in-a-table/</link>
		<comments>http://sqlkeys.wordpress.com/2012/02/10/get-list-of-columns-in-a-table/#comments</comments>
		<pubDate>Fri, 10 Feb 2012 14:45:38 +0000</pubDate>
		<dc:creator>Seth</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[list all columns]]></category>
		<category><![CDATA[list all columns except one]]></category>
		<category><![CDATA[list columns]]></category>
		<category><![CDATA[list sql columns]]></category>
		<category><![CDATA[sql columns]]></category>
		<category><![CDATA[sql fieldnames]]></category>
		<category><![CDATA[sql server]]></category>
		<category><![CDATA[sys.columns]]></category>
		<category><![CDATA[sys.objects]]></category>
		<category><![CDATA[table columns]]></category>

		<guid isPermaLink="false">http://sqlkeys.wordpress.com/?p=510</guid>
		<description><![CDATA[As you may know by now, there is no way (yet) to write a SQL Server SELECT statement, using the wildcard, to select all columns in a table except for any number of particular columns.  For example, if you wanted to return all fields from the Person.Address table except for the City field, you cannot &#8230; <a href="http://sqlkeys.wordpress.com/2012/02/10/get-list-of-columns-in-a-table/">Continue reading <span class="meta-nav">&#187;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlkeys.wordpress.com&amp;blog=24907369&amp;post=510&amp;subd=sqlkeys&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h3><span style="color:#0000ff;">As you may know by now, there is no way (yet) to write a SQL Server SELECT statement, using the wildcard, to select all columns in a table<strong> except for</strong> any number of particular columns</span>.  For example, if you wanted to return all fields from the Person.Address table except for the City field, you <strong>cannot</strong> write a query like this:</h3>
<pre>SELECT ( * -City ) FROM Person.Address</pre>
<p>If you need to select 99 of 100 columns in a table, you have to list all 99.  This can be a painful task.  For now, the best way to accomplish this is to <strong>generate a list of field names from the table</strong>, and copy them into your query.  Here&#8217;s how to do it.</p>
<p>Every database in SQL Server 2008 contains system views named <strong>sys.obects</strong> and<strong> sys.columns</strong>.  Sys.objects contains <span style="text-decoration:underline;">all database objects</span>: system tables, user tables, constraints, views, etc.  Sys.columns contains <span style="text-decoration:underline;">all columns from every table</span>, along with the same object_id of it&#8217;s parent object (the table).  By joining these system tables together, you can get a quick list of columns that you can copy and paste into your query:</p>
<pre>USE AdventureWorks
GO
SELECT sc.name ColumnName
FROM sys.objects so
JOIN sys.columns sc
ON so.object_id = sc.object_id
WHERE so.name = 'Contact'</pre>
<p style="text-align:center;"><a href="http://sqlkeys.files.wordpress.com/2012/02/sql12-e1328884509791.png?w=364"><img class="aligncenter size-large wp-image-611" title="sql1" src="http://sqlkeys.files.wordpress.com/2012/02/sql12-e1328884509791.png?w=364&#038;h=527" alt="" width="364" height="527" /></a></p>
<p><strong>This is certainly one query to memorize!</strong></p>
<p>To list columns from <strong>ANY</strong> user table, drop the table specification, add a filter on sys.objects for &#8216;type&#8217;, and include the table name by using the <strong>OBJECT_NAME</strong> function:</p>
<pre>USE AdventureWorks
GO
SELECT OBJECT_NAME(sc.OBJECT_ID) TableName, sc.name ColumnName
FROM sys.objects so
JOIN sys.columns sc
ON so.object_id = sc.object_id
WHERE so.type = 'U'</pre>
<p style="text-align:center;"><a href="http://sqlkeys.files.wordpress.com/2012/02/sql21-e1328884455459.png?w=595"><img class="aligncenter  wp-image-610" title="sql2" src="http://sqlkeys.files.wordpress.com/2012/02/sql21-e1328884455459.png?w=595&#038;h=747" alt="" width="595" height="747" /></a></p>
<p style="text-align:left;">This query can be taken even further by joining to the <strong>sys.types</strong> view, where <span style="text-decoration:underline;">data type metadata is stored</span>:</p>
<pre>USE AdventureWorks
GO
SELECT OBJECT_NAME(sc.OBJECT_ID) TableName, sc.name ColumnName,
t.name [DataType], sc.is_nullable Nullable, sc.is_identity Is_identity
FROM sys.objects so
JOIN sys.columns sc
ON so.object_id = sc.object_id
JOIN sys.types t
ON sc.user_type_id=t.user_type_id
WHERE so.type = 'U'</pre>
<p style="text-align:center;"><a href="http://sqlkeys.files.wordpress.com/2012/02/sql3-e1328884352386.png?w=653"><img class="aligncenter  wp-image-609" title="sql3" src="http://sqlkeys.files.wordpress.com/2012/02/sql3-e1328884352386.png?w=653&#038;h=754" alt="" width="653" height="754" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlkeys.wordpress.com/510/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlkeys.wordpress.com/510/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlkeys.wordpress.com/510/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlkeys.wordpress.com/510/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlkeys.wordpress.com/510/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlkeys.wordpress.com/510/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlkeys.wordpress.com/510/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlkeys.wordpress.com/510/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlkeys.wordpress.com/510/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlkeys.wordpress.com/510/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlkeys.wordpress.com/510/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlkeys.wordpress.com/510/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlkeys.wordpress.com/510/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlkeys.wordpress.com/510/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlkeys.wordpress.com&amp;blog=24907369&amp;post=510&amp;subd=sqlkeys&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlkeys.wordpress.com/2012/02/10/get-list-of-columns-in-a-table/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b9f68ea70e072376ab12b8fc92d4fd1c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">SD</media:title>
		</media:content>

		<media:content url="http://sqlkeys.files.wordpress.com/2012/02/sql12-e1328884509791.png?w=364" medium="image">
			<media:title type="html">sql1</media:title>
		</media:content>

		<media:content url="http://sqlkeys.files.wordpress.com/2012/02/sql21-e1328884455459.png?w=595" medium="image">
			<media:title type="html">sql2</media:title>
		</media:content>

		<media:content url="http://sqlkeys.files.wordpress.com/2012/02/sql3-e1328884352386.png?w=653" medium="image">
			<media:title type="html">sql3</media:title>
		</media:content>
	</item>
		<item>
		<title>Grant permissions to SQL Server database users on specific objects</title>
		<link>http://sqlkeys.wordpress.com/2011/11/23/grant-permissions-to-sql-server-database-users-on-specific-objects/</link>
		<comments>http://sqlkeys.wordpress.com/2011/11/23/grant-permissions-to-sql-server-database-users-on-specific-objects/#comments</comments>
		<pubDate>Wed, 23 Nov 2011 13:27:49 +0000</pubDate>
		<dc:creator>Seth</dc:creator>
				<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://sqlkeys.wordpress.com/?p=491</guid>
		<description><![CDATA[Need to allow a user access to only specific tables or other database objects, but not to the entire database? Get granular with the GRANT statement. &#160; To apply granular permissions to a specific object, like a table, use the GRANT [permission] ON [object] TO [user] format. To grant select permissions on a table to a database &#8230; <a href="http://sqlkeys.wordpress.com/2011/11/23/grant-permissions-to-sql-server-database-users-on-specific-objects/">Continue reading <span class="meta-nav">&#187;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlkeys.wordpress.com&amp;blog=24907369&amp;post=491&amp;subd=sqlkeys&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h3><span style="color:#000000;">Need to allow a user access to only specific tables or other database objects, but not to the entire database? <span style="color:#0000ff;"><strong>Get granular with the GRANT statement.</strong></span></span></h3>
<blockquote><p>&nbsp;</p></blockquote>
<p>To apply granular permissions to a specific object, like a table, use the<strong> GRANT [permission] ON [object] TO [user]</strong> format.</p>
<div><strong>To grant select permissions on a table to a database user:</strong></div>
<div></div>
<div>
<div><a href="http://knol.google.com/k/-/-/3b5bdtdbcdho5/38gr05/capture.png"><img src="http://knol.google.com/k/-/-/3b5bdtdbcdho5/38gr05/capture.png" alt="" border="0" /></a></div>
</div>
<div></div>
<div>If your login has no User Mapping to any database user, you will receive an error like this:</div>
<div></div>
<div><span style="color:#ff0000;">Msg 15151, Level 16, State 1, Line 1</span></div>
<div><span style="color:#ff0000;">Cannot find the user &#8216;dba_test&#8217;, because it does not exist or you do not have permission</span>.</div>
<div></div>
<div>&#8230; and a database user <strong>needs to be created for the login:</strong></div>
<div></div>
<div>
<div><a href="http://knol.google.com/k/-/-/3b5bdtdbcdho5/38gr05/capture%20(1).png"><img src="http://knol.google.com/k/-/-/3b5bdtdbcdho5/38gr05/capture%20(1).png" alt="" border="0" /></a></div>
</div>
<div><strong>___________________________________________________________________________________</strong></div>
<div><strong><br />
</strong></div>
<div><strong>To grant execute permissions on a stored procedure to a database user:</strong></div>
<div></div>
<div>
<div><a href="http://knol.google.com/k/-/-/3b5bdtdbcdho5/38gr05/capture%20(2).png"><img src="http://knol.google.com/k/-/-/3b5bdtdbcdho5/38gr05/capture%20(2).png" alt="" border="0" /></a></div>
</div>
<div><strong><br />
</strong></div>
<div><a href="http://msdn.microsoft.com/en-us/library/ms187965.aspx">http://msdn.microsoft.com/en-us/library/ms187965.aspx</a></div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlkeys.wordpress.com/491/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlkeys.wordpress.com/491/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlkeys.wordpress.com/491/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlkeys.wordpress.com/491/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlkeys.wordpress.com/491/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlkeys.wordpress.com/491/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlkeys.wordpress.com/491/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlkeys.wordpress.com/491/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlkeys.wordpress.com/491/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlkeys.wordpress.com/491/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlkeys.wordpress.com/491/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlkeys.wordpress.com/491/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlkeys.wordpress.com/491/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlkeys.wordpress.com/491/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlkeys.wordpress.com&amp;blog=24907369&amp;post=491&amp;subd=sqlkeys&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlkeys.wordpress.com/2011/11/23/grant-permissions-to-sql-server-database-users-on-specific-objects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b9f68ea70e072376ab12b8fc92d4fd1c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">SD</media:title>
		</media:content>

		<media:content url="http://knol.google.com/k/-/-/3b5bdtdbcdho5/38gr05/capture.png" medium="image" />

		<media:content url="http://knol.google.com/k/-/-/3b5bdtdbcdho5/38gr05/capture%20(1).png" medium="image" />

		<media:content url="http://knol.google.com/k/-/-/3b5bdtdbcdho5/38gr05/capture%20(2).png" medium="image" />
	</item>
		<item>
		<title>Increasing the mimimum memory used per query</title>
		<link>http://sqlkeys.wordpress.com/2011/10/27/increasing-the-mimimum-memory-used-per-query/</link>
		<comments>http://sqlkeys.wordpress.com/2011/10/27/increasing-the-mimimum-memory-used-per-query/#comments</comments>
		<pubDate>Thu, 27 Oct 2011 12:39:39 +0000</pubDate>
		<dc:creator>Seth</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[min memory sql server]]></category>
		<category><![CDATA[minimum memory per query]]></category>

		<guid isPermaLink="false">http://sqlkeys.wordpress.com/?p=441</guid>
		<description><![CDATA[SQL Server&#8217;s sp_configure settings contains a setting named &#8216;min memory per query (KB)&#8217;. This setting allows you to set the default minimum amount of RAM that&#8217;s allocated for each query &#8212; but should be used with care. Like many SQL Server settings, the default setting is best for most situations. However, if you have RAM &#8230; <a href="http://sqlkeys.wordpress.com/2011/10/27/increasing-the-mimimum-memory-used-per-query/">Continue reading <span class="meta-nav">&#187;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlkeys.wordpress.com&amp;blog=24907369&amp;post=441&amp;subd=sqlkeys&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>SQL Server&#8217;s <strong>sp_configure</strong> settings contains a setting named &#8216;min memory per query (KB)&#8217;. This setting allows you to set the default minimum amount of RAM that&#8217;s allocated for each query &#8212; <span style="text-decoration:underline;">but should be used with care</span>. Like many SQL Server settings, the default setting is best for most situations. However, <strong>if you have RAM to burn</strong>, <a href="http://msdn.microsoft.com/en-us/library/ms181047.aspx">BOL</a> offers that increasing this setting could have a positive impact on small queries:</p>
<blockquote><p><span style="color:#ff0000;"><strong>&#8220;Increasing the value of min memory per query may improve performance for some small to medium-sized queries, but doing so could lead to increased competition for memory resources.&#8221;</strong></span></p></blockquote>
<p>Updates to the &#8216;min memory per query (KB)&#8217; setting can be done like this:</p>
<pre>--first, turn on advanced options
SP_CONFIGURE 'show advanced options', 1
GO
RECONFIGURE
GO
--then, set new value - default value is 1024KB, this increases it to 2MB
SP_CONFIGURE 'min memory per query (KB)',2048
GO
RECONFIGURE WITH OVERRIDE
GO
--now, display new value
SP_CONFIGURE 'min memory per query (KB)'
GO
RECONFIGURE WITH OVERRIDE
GO
___________________________________________________________________________________________________</pre>
<p><a href="http://sqlkeys.files.wordpress.com/2011/10/capture.png"><img class="size-large wp-image-443 alignleft" title="Capture" src="http://sqlkeys.files.wordpress.com/2011/10/capture.png?w=300&#038;h=96" alt="" width="300" height="96" /></a></p>
<p><a href="http://sqlkeys.files.wordpress.com/2011/10/capture1.png"><img class="size-large wp-image-445 alignleft" title="Capture" src="http://sqlkeys.files.wordpress.com/2011/10/capture1.png?w=300&#038;h=49" alt="" width="300" height="49" /></a></p>
<p><a href="http://msdn.microsoft.com/en-us/library/ms181047.aspx">http://msdn.microsoft.com/en-us/library/ms181047.aspx</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlkeys.wordpress.com/441/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlkeys.wordpress.com/441/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlkeys.wordpress.com/441/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlkeys.wordpress.com/441/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlkeys.wordpress.com/441/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlkeys.wordpress.com/441/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlkeys.wordpress.com/441/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlkeys.wordpress.com/441/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlkeys.wordpress.com/441/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlkeys.wordpress.com/441/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlkeys.wordpress.com/441/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlkeys.wordpress.com/441/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlkeys.wordpress.com/441/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlkeys.wordpress.com/441/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlkeys.wordpress.com&amp;blog=24907369&amp;post=441&amp;subd=sqlkeys&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlkeys.wordpress.com/2011/10/27/increasing-the-mimimum-memory-used-per-query/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b9f68ea70e072376ab12b8fc92d4fd1c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">SD</media:title>
		</media:content>

		<media:content url="http://sqlkeys.files.wordpress.com/2011/10/capture.png?w=300" medium="image">
			<media:title type="html">Capture</media:title>
		</media:content>

		<media:content url="http://sqlkeys.files.wordpress.com/2011/10/capture1.png?w=300" medium="image">
			<media:title type="html">Capture</media:title>
		</media:content>
	</item>
		<item>
		<title>Copy table schema only</title>
		<link>http://sqlkeys.wordpress.com/2011/06/29/copy-table-schema-only/</link>
		<comments>http://sqlkeys.wordpress.com/2011/06/29/copy-table-schema-only/#comments</comments>
		<pubDate>Wed, 29 Jun 2011 19:05:19 +0000</pubDate>
		<dc:creator>Seth</dc:creator>
				<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://sqlkeys.resistancenet.com/?p=283</guid>
		<description><![CDATA[Need to duplicate a table&#8217;s schema?  Use a SELECT&#8230;INTO&#8230;FROM  statement: SELECT * INTO new_tbl FROM old_tbl This will create a copy of the table, data and all.  What if you don&#8217;t want the data copied with the schema?  My friend Alessandro Basso uses this method: SELECT * INTO new_tbl FROM old_tbl WHERE 1=2 Genius!<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlkeys.wordpress.com&amp;blog=24907369&amp;post=283&amp;subd=sqlkeys&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Need to duplicate a table&#8217;s schema?  Use a SELECT&#8230;INTO&#8230;FROM  statement:</p>
<blockquote><p>SELECT * INTO new_tbl<br />
FROM old_tbl</p></blockquote>
<p>This will create a copy of the table, data and all.  What if you don&#8217;t want the data copied with the schema?  My friend <a href="http://www.alessandrobasso.tk/">Alessandro Basso</a> uses this method:</p>
<blockquote><p>SELECT * INTO new_tbl<br />
FROM old_tbl<br />
WHERE 1=2</p></blockquote>
<div>Genius!</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlkeys.wordpress.com/283/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlkeys.wordpress.com/283/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlkeys.wordpress.com/283/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlkeys.wordpress.com/283/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlkeys.wordpress.com/283/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlkeys.wordpress.com/283/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlkeys.wordpress.com/283/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlkeys.wordpress.com/283/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlkeys.wordpress.com/283/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlkeys.wordpress.com/283/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlkeys.wordpress.com/283/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlkeys.wordpress.com/283/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlkeys.wordpress.com/283/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlkeys.wordpress.com/283/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlkeys.wordpress.com&amp;blog=24907369&amp;post=283&amp;subd=sqlkeys&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlkeys.wordpress.com/2011/06/29/copy-table-schema-only/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b9f68ea70e072376ab12b8fc92d4fd1c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">SD</media:title>
		</media:content>
	</item>
		<item>
		<title>Grouping with ROW_NUMBER</title>
		<link>http://sqlkeys.wordpress.com/2011/06/16/grouping-by-row_number/</link>
		<comments>http://sqlkeys.wordpress.com/2011/06/16/grouping-by-row_number/#comments</comments>
		<pubDate>Thu, 16 Jun 2011 17:04:21 +0000</pubDate>
		<dc:creator>Seth</dc:creator>
				<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://sqlkeys.resistancenet.com/?p=257</guid>
		<description><![CDATA[Want to group a result set by only one field, but include others in the result set?  You can use the ROW_NUMBER function with its PARTITION BY parameter. To play with this, let&#8217;s create some sample data: Now we have a table with sample data: Using the data we just created, we want to show &#8230; <a href="http://sqlkeys.wordpress.com/2011/06/16/grouping-by-row_number/">Continue reading <span class="meta-nav">&#187;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlkeys.wordpress.com&amp;blog=24907369&amp;post=257&amp;subd=sqlkeys&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Want to group a result set by only one field, but include others in the result set?  You can use the <strong>ROW_NUMBER</strong> function with its <strong>PARTITION BY</strong> parameter.</p>
<p>To play with this, let&#8217;s create some sample data:</p>
<p><a href="http://sqlkeys.files.wordpress.com/2011/06/screen-shot-2011-06-16-at-3-07-08-pm1.png"><img class="alignnone size-full wp-image-274" title="Screen shot 2011-06-16 at 3.07.08 PM" src="http://sqlkeys.files.wordpress.com/2011/06/screen-shot-2011-06-16-at-3-07-08-pm1.png?w=750" alt=""   /></a></p>
<p><a href="http://sqlkeys.files.wordpress.com/2011/06/screen-shot-2011-06-16-at-2-30-34-pm12.png"><img class="alignnone size-full wp-image-264" title="Screen shot 2011-06-16 at 2.30.34 PM" src="http://sqlkeys.files.wordpress.com/2011/06/screen-shot-2011-06-16-at-2-30-34-pm12.png?w=750" alt=""   /></a></p>
<p>Now we have a table with sample data:</p>
<p><a href="http://sqlkeys.files.wordpress.com/2011/06/screen-shot-2011-06-16-at-2-34-29-pm1.png"><img class="alignnone size-full wp-image-265" title="Screen shot 2011-06-16 at 2.34.29 PM" src="http://sqlkeys.files.wordpress.com/2011/06/screen-shot-2011-06-16-at-2-34-29-pm1.png?w=750" alt=""   /></a></p>
<p>Using the data we just created, we want to show only the most recent transaction for EACH customer.   We can do a simple GROUP BY, but if we include TransactionID in the result set, we are forced to get a record for each TransactionID, since it has to be contained in the GROUP BY&#8217;s list of non-aggregates:</p>
<p><a href="http://sqlkeys.files.wordpress.com/2011/06/screen-shot-2011-06-16-at-2-50-53-pm1.png"><img class="alignnone size-full wp-image-270" title="Screen shot 2011-06-16 at 2.50.53 PM" src="http://sqlkeys.files.wordpress.com/2011/06/screen-shot-2011-06-16-at-2-50-53-pm1.png?w=750" alt=""   /></a></p>
<p><a href="http://sqlkeys.files.wordpress.com/2011/06/screen-shot-2011-06-16-at-2-50-59-pm1.png"><img class="alignnone size-full wp-image-271" title="Screen shot 2011-06-16 at 2.50.59 PM" src="http://sqlkeys.files.wordpress.com/2011/06/screen-shot-2011-06-16-at-2-50-59-pm1.png?w=750" alt=""   /></a></p>
<p>We get the full result set &#8211; not what we want.  To include TransactionID (or any other field that may be in the table) in the result set, but grouping only on CustID, we can include the ROW_NUMBER function in the select list, using the PARTITION BY clause:</p>
<p><a href="http://sqlkeys.files.wordpress.com/2011/06/screen-shot-2011-06-16-at-3-07-16-pm1.png"><img class="alignnone size-full wp-image-275" title="Screen shot 2011-06-16 at 3.07.16 PM" src="http://sqlkeys.files.wordpress.com/2011/06/screen-shot-2011-06-16-at-3-07-16-pm1.png?w=750" alt=""   /></a></p>
<p>We get this:</p>
<p><a href="http://sqlkeys.files.wordpress.com/2011/06/screen-shot-2011-06-16-at-2-46-46-pm1.png"><img class="alignnone size-full wp-image-268" title="Screen shot 2011-06-16 at 2.46.46 PM" src="http://sqlkeys.files.wordpress.com/2011/06/screen-shot-2011-06-16-at-2-46-46-pm1.png?w=750" alt=""   /></a></p>
<p>Using the ROW_NUMBER function in the select list (with out the PARTITION BY parameter) simply gives us the unique row number for each record.  When we use the PARTITION BY clause, it groups on CustID.  The ORDER BY clause is required, and necessary for our results &#8211; this allows us to make the most recent SaleDate = row 1.</p>
<p>&nbsp;</p>
<p><em>I give credit to Dan Humphries for showing examples of ROW_NUMBER <a href="http://www.sqlservercentral.com/Forums/Topic1126587-149-1.aspx">here</a>.</em></p>
<p><em><a href="http://msdn.microsoft.com/en-us/library/ms186734.aspx">http://msdn.microsoft.com/en-us/library/ms186734.aspx</a><br />
</em></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlkeys.wordpress.com/257/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlkeys.wordpress.com/257/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlkeys.wordpress.com/257/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlkeys.wordpress.com/257/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlkeys.wordpress.com/257/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlkeys.wordpress.com/257/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlkeys.wordpress.com/257/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlkeys.wordpress.com/257/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlkeys.wordpress.com/257/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlkeys.wordpress.com/257/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlkeys.wordpress.com/257/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlkeys.wordpress.com/257/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlkeys.wordpress.com/257/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlkeys.wordpress.com/257/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlkeys.wordpress.com&amp;blog=24907369&amp;post=257&amp;subd=sqlkeys&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlkeys.wordpress.com/2011/06/16/grouping-by-row_number/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b9f68ea70e072376ab12b8fc92d4fd1c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">SD</media:title>
		</media:content>

		<media:content url="http://sqlkeys.files.wordpress.com/2011/06/screen-shot-2011-06-16-at-3-07-08-pm1.png" medium="image">
			<media:title type="html">Screen shot 2011-06-16 at 3.07.08 PM</media:title>
		</media:content>

		<media:content url="http://sqlkeys.files.wordpress.com/2011/06/screen-shot-2011-06-16-at-2-30-34-pm12.png" medium="image">
			<media:title type="html">Screen shot 2011-06-16 at 2.30.34 PM</media:title>
		</media:content>

		<media:content url="http://sqlkeys.files.wordpress.com/2011/06/screen-shot-2011-06-16-at-2-34-29-pm1.png" medium="image">
			<media:title type="html">Screen shot 2011-06-16 at 2.34.29 PM</media:title>
		</media:content>

		<media:content url="http://sqlkeys.files.wordpress.com/2011/06/screen-shot-2011-06-16-at-2-50-53-pm1.png" medium="image">
			<media:title type="html">Screen shot 2011-06-16 at 2.50.53 PM</media:title>
		</media:content>

		<media:content url="http://sqlkeys.files.wordpress.com/2011/06/screen-shot-2011-06-16-at-2-50-59-pm1.png" medium="image">
			<media:title type="html">Screen shot 2011-06-16 at 2.50.59 PM</media:title>
		</media:content>

		<media:content url="http://sqlkeys.files.wordpress.com/2011/06/screen-shot-2011-06-16-at-3-07-16-pm1.png" medium="image">
			<media:title type="html">Screen shot 2011-06-16 at 3.07.16 PM</media:title>
		</media:content>

		<media:content url="http://sqlkeys.files.wordpress.com/2011/06/screen-shot-2011-06-16-at-2-46-46-pm1.png" medium="image">
			<media:title type="html">Screen shot 2011-06-16 at 2.46.46 PM</media:title>
		</media:content>
	</item>
		<item>
		<title>Windows 7 User Access Control Default Setting Blocks Unsupported Applications</title>
		<link>http://sqlkeys.wordpress.com/2010/07/14/windows-7-user-access-control-changes/</link>
		<comments>http://sqlkeys.wordpress.com/2010/07/14/windows-7-user-access-control-changes/#comments</comments>
		<pubDate>Wed, 14 Jul 2010 19:28:22 +0000</pubDate>
		<dc:creator>Seth</dc:creator>
				<category><![CDATA[Everything Else]]></category>
		<category><![CDATA[UAC]]></category>
		<category><![CDATA[user access control]]></category>
		<category><![CDATA[Windows 7]]></category>

		<guid isPermaLink="false">http://sqlkeys.resistancenet.com/?p=246</guid>
		<description><![CDATA[While testing a backup application (that I wrote in .NET) on a 64-bit Windows 7 VM today, the initial registry reads failed (although, weirdly, the writes succeeded). This app has worked well on Windows XP in the past. After a bit of Googling, I found the solution. The problem was that the default setting for &#8230; <a href="http://sqlkeys.wordpress.com/2010/07/14/windows-7-user-access-control-changes/">Continue reading <span class="meta-nav">&#187;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlkeys.wordpress.com&amp;blog=24907369&amp;post=246&amp;subd=sqlkeys&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>While testing a backup application (that I wrote in .NET) on a 64-bit Windows 7 VM today, the initial registry reads failed (although, weirdly, the writes succeeded). This app has worked well on Windows XP in the past. After a bit of Googling, I found the solution. The problem was that the default setting for the UAC (User Access Control) feature had been denying the app permission to read the registry settings. The UAC should normally notify the user when a program (or user, depending on the UAC setting) tries to make certain changes to Windows. My application, however, was not triggering a UAC notification, but its registry reads were denied nevertheless. Setting UAC to <strong>Never notify</strong> fixed it. The default UAC setting on Windows 7 is supposed to notify the user when programs attempt to make changes to Windows. The reason that a notification was not raised was because my application is not certified for Windows 7 and/or does not support UAC.</p>
<p><a href="http://sqlkeys.files.wordpress.com/2010/07/screen-shot-2010-07-14-at-5-25-54-pm1.png"><img class="alignnone size-full wp-image-247" title="Screen shot 2010-07-14 at 5.25.54 PM" src="http://sqlkeys.files.wordpress.com/2010/07/screen-shot-2010-07-14-at-5-25-54-pm1.png?w=750" alt=""   /></a></p>
<p>To change the UAC setting, click the Start button type &#8216;UAC&#8217; in the Search box. Open the UAC and change to the desired setting.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlkeys.wordpress.com/246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlkeys.wordpress.com/246/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlkeys.wordpress.com/246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlkeys.wordpress.com/246/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlkeys.wordpress.com/246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlkeys.wordpress.com/246/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlkeys.wordpress.com/246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlkeys.wordpress.com/246/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlkeys.wordpress.com/246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlkeys.wordpress.com/246/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlkeys.wordpress.com/246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlkeys.wordpress.com/246/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlkeys.wordpress.com/246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlkeys.wordpress.com/246/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlkeys.wordpress.com&amp;blog=24907369&amp;post=246&amp;subd=sqlkeys&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlkeys.wordpress.com/2010/07/14/windows-7-user-access-control-changes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b9f68ea70e072376ab12b8fc92d4fd1c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">SD</media:title>
		</media:content>

		<media:content url="http://sqlkeys.files.wordpress.com/2010/07/screen-shot-2010-07-14-at-5-25-54-pm1.png" medium="image">
			<media:title type="html">Screen shot 2010-07-14 at 5.25.54 PM</media:title>
		</media:content>
	</item>
		<item>
		<title>SSPI stands for&#8230;?</title>
		<link>http://sqlkeys.wordpress.com/2010/07/06/sspi-stands-for/</link>
		<comments>http://sqlkeys.wordpress.com/2010/07/06/sspi-stands-for/#comments</comments>
		<pubDate>Tue, 06 Jul 2010 16:16:29 +0000</pubDate>
		<dc:creator>Seth</dc:creator>
				<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://sqlkeys.resistancenet.com/?p=234</guid>
		<description><![CDATA[The acronym SSPI stands for Microsoft&#8217;s Security Support Provider Interface. http://technet.microsoft.com/en-us/library/bb742535.aspx<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlkeys.wordpress.com&amp;blog=24907369&amp;post=234&amp;subd=sqlkeys&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The acronym SSPI stands for Microsoft&#8217;s <strong>Security Support Provider Interface.</strong></p>
<p><a href="http://technet.microsoft.com/en-us/library/bb742535.aspx">http://technet.microsoft.com/en-us/library/bb742535.aspx</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlkeys.wordpress.com/234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlkeys.wordpress.com/234/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlkeys.wordpress.com/234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlkeys.wordpress.com/234/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlkeys.wordpress.com/234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlkeys.wordpress.com/234/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlkeys.wordpress.com/234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlkeys.wordpress.com/234/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlkeys.wordpress.com/234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlkeys.wordpress.com/234/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlkeys.wordpress.com/234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlkeys.wordpress.com/234/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlkeys.wordpress.com/234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlkeys.wordpress.com/234/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlkeys.wordpress.com&amp;blog=24907369&amp;post=234&amp;subd=sqlkeys&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlkeys.wordpress.com/2010/07/06/sspi-stands-for/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b9f68ea70e072376ab12b8fc92d4fd1c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">SD</media:title>
		</media:content>
	</item>
		<item>
		<title>BRAD MCGEHEE ON INDEXES</title>
		<link>http://sqlkeys.wordpress.com/2010/05/05/brad-mcgehee-on-indexes/</link>
		<comments>http://sqlkeys.wordpress.com/2010/05/05/brad-mcgehee-on-indexes/#comments</comments>
		<pubDate>Wed, 05 May 2010 13:44:29 +0000</pubDate>
		<dc:creator>Seth</dc:creator>
				<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://sqlkeys.resistancenet.com/?p=231</guid>
		<description><![CDATA[Here&#8217;s a link to a great article on index implementation by an expert DBA, Brad McGehee. http://www.sql-server-performance.com/tips/composite_indexes_p1.aspx<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlkeys.wordpress.com&amp;blog=24907369&amp;post=231&amp;subd=sqlkeys&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a link to a great article on index implementation by an expert DBA, Brad McGehee.</p>
<p><a href="http://www.sql-server-performance.com/tips/composite_indexes_p1.aspx">http://www.sql-server-performance.com/tips/composite_indexes_p1.aspx</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlkeys.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlkeys.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlkeys.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlkeys.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlkeys.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlkeys.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlkeys.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlkeys.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlkeys.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlkeys.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlkeys.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlkeys.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlkeys.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlkeys.wordpress.com/231/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlkeys.wordpress.com&amp;blog=24907369&amp;post=231&amp;subd=sqlkeys&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlkeys.wordpress.com/2010/05/05/brad-mcgehee-on-indexes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b9f68ea70e072376ab12b8fc92d4fd1c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">SD</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL Server 2008 Prevent Saving Changes Setting</title>
		<link>http://sqlkeys.wordpress.com/2010/04/28/sql-server-2008-prevent-saving-changes-setting/</link>
		<comments>http://sqlkeys.wordpress.com/2010/04/28/sql-server-2008-prevent-saving-changes-setting/#comments</comments>
		<pubDate>Wed, 28 Apr 2010 20:05:38 +0000</pubDate>
		<dc:creator>Seth</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[prevent saving changes]]></category>
		<category><![CDATA[prevent saving changes sql]]></category>
		<category><![CDATA[Prevent saving changes that require the table re-creation]]></category>
		<category><![CDATA[saving changes is not permitted]]></category>
		<category><![CDATA[sql server]]></category>

		<guid isPermaLink="false">http://sqlkeys.resistancenet.com/?p=214</guid>
		<description><![CDATA[SQL Server 2008 has a setting that PREVENTS saving certain table schema changes (such as changing column order) &#8211; and this setting is ENABLED by default. When I first encountered the effects of this setting, I was attempting to rearrange the column order of a table. Using the GUI, I went to the table design &#8230; <a href="http://sqlkeys.wordpress.com/2010/04/28/sql-server-2008-prevent-saving-changes-setting/">Continue reading <span class="meta-nav">&#187;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlkeys.wordpress.com&amp;blog=24907369&amp;post=214&amp;subd=sqlkeys&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h3><span style="color:#0000ff;">SQL Server 2008 has a setting that PREVENTS saving certain table schema changes (such as changing column order) &#8211; and this setting is ENABLED by default.</span></h3>
<p>When I first encountered the effects of this setting, I was attempting to rearrange the column order of a table. Using the GUI, I went to the table design view and moved one column in front of another.</p>
<p>When I hit &#8216;Save&#8217;, I received this message:</p>
<p><a href="http://sqlkeys.files.wordpress.com/2010/04/screen-shot-2010-04-28-at-5-34-26-pm1.png"><img class="alignnone size-full wp-image-218" title="Screen shot 2010-04-28 at 5.34.26 PM" src="http://sqlkeys.files.wordpress.com/2010/04/screen-shot-2010-04-28-at-5-34-26-pm1.png?w=750" alt=""   /></a></p>
<p>When a table&#8217;s schema is changed, the process that SQL Server performs drops the table and recreates it. The new setting that prevents this is called &#8216;<strong>Prevent saving changes that require table re-creation</strong>&#8216;, and it&#8217;s easy enough to turn off. I&#8217;m sure it has been put in place as a safeguard to prevent unintended table changes. To turn off the setting, go to (on the menu bar) <strong>Tools/Options/Designers/Table and Database Designers</strong>, then under the <strong>Table Options</strong> section, uncheck <strong>Prevent saving changes&#8230;</strong>.</p>
<p><a href="http://sqlkeys.files.wordpress.com/2010/04/screen-shot-2010-04-28-at-5-34-51-pm1.png"><img class="alignnone size-full wp-image-221" title="Screen shot 2010-04-28 at 5.34.51 PM" src="http://sqlkeys.files.wordpress.com/2010/04/screen-shot-2010-04-28-at-5-34-51-pm1.png?w=750" alt=""   /></a></p>
<p><a href="http://sqlkeys.files.wordpress.com/2010/04/screen-shot-2010-04-28-at-5-35-11-pm1.png"><img class="alignnone size-full wp-image-222" title="Screen shot 2010-04-28 at 5.35.11 PM" src="http://sqlkeys.files.wordpress.com/2010/04/screen-shot-2010-04-28-at-5-35-11-pm1.png?w=750" alt=""   /></a></p>
<p><a href="http://sqlkeys.files.wordpress.com/2010/04/screen-shot-2010-04-28-at-5-35-29-pm1.png"><img class="alignnone size-full wp-image-223" title="Screen shot 2010-04-28 at 5.35.29 PM" src="http://sqlkeys.files.wordpress.com/2010/04/screen-shot-2010-04-28-at-5-35-29-pm1.png?w=750" alt=""   /></a></p>
<p>Schema changes will not be blocked.  <strong>You&#8217;re welcome</strong>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlkeys.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlkeys.wordpress.com/214/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlkeys.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlkeys.wordpress.com/214/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlkeys.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlkeys.wordpress.com/214/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlkeys.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlkeys.wordpress.com/214/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlkeys.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlkeys.wordpress.com/214/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlkeys.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlkeys.wordpress.com/214/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlkeys.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlkeys.wordpress.com/214/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlkeys.wordpress.com&amp;blog=24907369&amp;post=214&amp;subd=sqlkeys&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlkeys.wordpress.com/2010/04/28/sql-server-2008-prevent-saving-changes-setting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b9f68ea70e072376ab12b8fc92d4fd1c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">SD</media:title>
		</media:content>

		<media:content url="http://sqlkeys.files.wordpress.com/2010/04/screen-shot-2010-04-28-at-5-34-26-pm1.png" medium="image">
			<media:title type="html">Screen shot 2010-04-28 at 5.34.26 PM</media:title>
		</media:content>

		<media:content url="http://sqlkeys.files.wordpress.com/2010/04/screen-shot-2010-04-28-at-5-34-51-pm1.png" medium="image">
			<media:title type="html">Screen shot 2010-04-28 at 5.34.51 PM</media:title>
		</media:content>

		<media:content url="http://sqlkeys.files.wordpress.com/2010/04/screen-shot-2010-04-28-at-5-35-11-pm1.png" medium="image">
			<media:title type="html">Screen shot 2010-04-28 at 5.35.11 PM</media:title>
		</media:content>

		<media:content url="http://sqlkeys.files.wordpress.com/2010/04/screen-shot-2010-04-28-at-5-35-29-pm1.png" medium="image">
			<media:title type="html">Screen shot 2010-04-28 at 5.35.29 PM</media:title>
		</media:content>
	</item>
		<item>
		<title>HOW TO GET CONDITIONAL SUM AGGREGATES IN A RECORDSET USING THE CASE STATEMENT</title>
		<link>http://sqlkeys.wordpress.com/2010/04/08/how-to-get-conditional-sum-aggregates-in-a-recordset-using-the-case-statement/</link>
		<comments>http://sqlkeys.wordpress.com/2010/04/08/how-to-get-conditional-sum-aggregates-in-a-recordset-using-the-case-statement/#comments</comments>
		<pubDate>Thu, 08 Apr 2010 19:45:29 +0000</pubDate>
		<dc:creator>Seth</dc:creator>
				<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://sqlkeys.resistancenet.com/?p=187</guid>
		<description><![CDATA[Today I was presented with a request to find a SQL Server-compatible substitute for the IIF function that MS Access uses. The IIF function is a conditional function; it evaluates a condition (test for TRUE or FALSE) and returns one configurable value or another depending on the result of the evaluation. SQL Server does not &#8230; <a href="http://sqlkeys.wordpress.com/2010/04/08/how-to-get-conditional-sum-aggregates-in-a-recordset-using-the-case-statement/">Continue reading <span class="meta-nav">&#187;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlkeys.wordpress.com&amp;blog=24907369&amp;post=187&amp;subd=sqlkeys&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Today I was presented with a request to find a SQL Server-compatible substitute for the IIF function that MS Access uses.  The IIF function is a conditional function; it evaluates a condition (test for TRUE or FALSE) and returns one configurable value or another depending on the result of the evaluation.  SQL Server does not have the IIF function, but it can easily perform the same operations using a CASE statement.  The scenario I was shown today used the IIF function wrapped in a SUM function, effectively adding a &#8217;1&#8242; for each record having a certain value in the evaluated field.</p>
<p>To demonstrate how SQL Server can solve this problem,  I&#8217;m going to use the AdventureWorks database and the Production.Product table.  This table has a Color field.  I want to find (in one query) the number of records for each respective color (or no color: NULL).  Here&#8217;s a quick shot of part of the table:</p>
<p><a href="http://sqlkeys.files.wordpress.com/2010/04/screen-shot-2010-04-08-at-5-28-12-pm1.png"><img src="http://sqlkeys.files.wordpress.com/2010/04/screen-shot-2010-04-08-at-5-28-12-pm1.png?w=750" alt="" title="Screen shot 2010-04-08 at 5.28.12 PM"   class="alignnone size-full wp-image-188" /></a></p>
<p>I can see that there are the colors Black and Silver in the table, along with many NULLs.  To get the count of records having the color Black, I can run the following:</p>
<p><a href="http://sqlkeys.files.wordpress.com/2010/04/screen-shot-2010-04-08-at-5-33-31-pm1.png"><img src="http://sqlkeys.files.wordpress.com/2010/04/screen-shot-2010-04-08-at-5-33-31-pm1.png?w=750" alt="" title="Screen shot 2010-04-08 at 5.33.31 PM"   class="alignnone size-full wp-image-191" /></a></p>
<p><a href="http://sqlkeys.files.wordpress.com/2010/04/screen-shot-2010-04-08-at-5-34-49-pm1.png"><img src="http://sqlkeys.files.wordpress.com/2010/04/screen-shot-2010-04-08-at-5-34-49-pm1.png?w=750" alt="" title="Screen shot 2010-04-08 at 5.34.49 PM"   class="alignnone size-full wp-image-194" /></a></p>
<p>That gives me a count of 93 records.  But how many different colors are there?  To find out, I&#8217;ll get all the DISTINCT Color values:</p>
<p><a href="http://sqlkeys.files.wordpress.com/2010/04/screen-shot-2010-04-08-at-5-37-11-pm1.png"><img src="http://sqlkeys.files.wordpress.com/2010/04/screen-shot-2010-04-08-at-5-37-11-pm1.png?w=750" alt="" title="Screen shot 2010-04-08 at 5.37.11 PM"   class="alignnone size-full wp-image-196" /></a></p>
<p><a href="http://sqlkeys.files.wordpress.com/2010/04/screen-shot-2010-04-08-at-5-37-45-pm1.png"><img src="http://sqlkeys.files.wordpress.com/2010/04/screen-shot-2010-04-08-at-5-37-45-pm1.png?w=750" alt="" title="Screen shot 2010-04-08 at 5.37.45 PM"   class="alignnone size-full wp-image-197" /></a></p>
<p>NOW I can formulate my entire query accurately, getting a total count, NULLS count, and counts for every color:</p>
<p><a href="http://sqlkeys.files.wordpress.com/2010/04/screen-shot-2010-04-08-at-5-53-01-pm1.png"><img src="http://sqlkeys.files.wordpress.com/2010/04/screen-shot-2010-04-08-at-5-53-01-pm1.png?w=750" alt="" title="Screen shot 2010-04-08 at 5.53.01 PM"   class="alignnone size-full wp-image-207" /></a></p>
<p><a href="http://sqlkeys.files.wordpress.com/2010/04/screen-shot-2010-04-08-at-5-56-42-pm1.png"><img src="http://sqlkeys.files.wordpress.com/2010/04/screen-shot-2010-04-08-at-5-56-42-pm1.png?w=750" alt="" title="Screen shot 2010-04-08 at 5.56.42 PM"   class="alignnone size-full wp-image-211" /></a></p>
<p>Looks good!</p>
<p><a href="http://www.techonthenet.com/access/functions/advanced/iif.php">Access IIF statement</a><br />
<a href="http://msdn.microsoft.com/en-us/library/ms181765.aspx">CASE statement</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlkeys.wordpress.com/187/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlkeys.wordpress.com/187/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlkeys.wordpress.com/187/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlkeys.wordpress.com/187/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlkeys.wordpress.com/187/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlkeys.wordpress.com/187/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlkeys.wordpress.com/187/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlkeys.wordpress.com/187/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlkeys.wordpress.com/187/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlkeys.wordpress.com/187/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlkeys.wordpress.com/187/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlkeys.wordpress.com/187/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlkeys.wordpress.com/187/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlkeys.wordpress.com/187/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sqlkeys.wordpress.com&amp;blog=24907369&amp;post=187&amp;subd=sqlkeys&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sqlkeys.wordpress.com/2010/04/08/how-to-get-conditional-sum-aggregates-in-a-recordset-using-the-case-statement/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b9f68ea70e072376ab12b8fc92d4fd1c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">SD</media:title>
		</media:content>

		<media:content url="http://sqlkeys.files.wordpress.com/2010/04/screen-shot-2010-04-08-at-5-28-12-pm1.png" medium="image">
			<media:title type="html">Screen shot 2010-04-08 at 5.28.12 PM</media:title>
		</media:content>

		<media:content url="http://sqlkeys.files.wordpress.com/2010/04/screen-shot-2010-04-08-at-5-33-31-pm1.png" medium="image">
			<media:title type="html">Screen shot 2010-04-08 at 5.33.31 PM</media:title>
		</media:content>

		<media:content url="http://sqlkeys.files.wordpress.com/2010/04/screen-shot-2010-04-08-at-5-34-49-pm1.png" medium="image">
			<media:title type="html">Screen shot 2010-04-08 at 5.34.49 PM</media:title>
		</media:content>

		<media:content url="http://sqlkeys.files.wordpress.com/2010/04/screen-shot-2010-04-08-at-5-37-11-pm1.png" medium="image">
			<media:title type="html">Screen shot 2010-04-08 at 5.37.11 PM</media:title>
		</media:content>

		<media:content url="http://sqlkeys.files.wordpress.com/2010/04/screen-shot-2010-04-08-at-5-37-45-pm1.png" medium="image">
			<media:title type="html">Screen shot 2010-04-08 at 5.37.45 PM</media:title>
		</media:content>

		<media:content url="http://sqlkeys.files.wordpress.com/2010/04/screen-shot-2010-04-08-at-5-53-01-pm1.png" medium="image">
			<media:title type="html">Screen shot 2010-04-08 at 5.53.01 PM</media:title>
		</media:content>

		<media:content url="http://sqlkeys.files.wordpress.com/2010/04/screen-shot-2010-04-08-at-5-56-42-pm1.png" medium="image">
			<media:title type="html">Screen shot 2010-04-08 at 5.56.42 PM</media:title>
		</media:content>
	</item>
	</channel>
</rss>
