<?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>Pressing the Red Button &#187; microsoft sql server</title>
	<atom:link href="http://www.pressthered.com/tag/microsoft_sql_server/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.pressthered.com</link>
	<description>Adventures in Software Development</description>
	<lastBuildDate>Sun, 05 Sep 2010 16:55:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Creating Temporary Tables in SQL Server</title>
		<link>http://www.pressthered.com/creating_temporary_tables_in_sql_server/</link>
		<comments>http://www.pressthered.com/creating_temporary_tables_in_sql_server/#comments</comments>
		<pubDate>Sat, 03 Oct 2009 06:50:03 +0000</pubDate>
		<dc:creator>jim.richmond</dc:creator>
				<category><![CDATA[Tech Tips]]></category>
		<category><![CDATA[microsoft sql server]]></category>

		<guid isPermaLink="false">http://www.pressthered.com/?p=579</guid>
		<description><![CDATA[Here are three methods of creating and working with temporary tables in Microsoft SQL Server:
Method 1: Select Into
This is a quick and dirty method to create a temporary table. Compared to the other methods, you do not have to define the column names. Just add the &#8216;into #temptablename&#8217; at the end of the columns you [...]]]></description>
			<content:encoded><![CDATA[<p>Here are three methods of creating and working with temporary tables in Microsoft SQL Server:</p>
<p><strong>Method 1: Select Into</strong><br />
This is a quick and dirty method to create a temporary table. Compared to the other methods, you do not have to define the column names. Just add the &#8216;into #temptablename&#8217; at the end of the columns you want selected.</p>
<pre name="code" class="sql">
select id, code
into #mytemptable
from sourcetable

--view the data
select * from #mytemptable
</pre>
<p><strong>Method 2: Create Table </strong><br />
Use this method if you want more control of the definition of the table and column types</p>
<pre name="code" class="sql">
CREATE TABLE #mytemptable (
dataid int,
description varchar(30) )

-- insert some data into it
insert into #mytemptable
select id, code from sourcetable

-- view the data
select * from #mytemptable

-- drop the table if you want to
drop table #mytemptable
</pre>
<p><strong>Method 3: Table Variable</strong><br />
This method is useful for programming stored procedures and user functions. Once you define the table, you can take advantage of passing table variables back and forth between code.</p>
<pre name="code" class="sql">
DECLARE @mytemptable TABLE (
dataid int,
description varchar(30) )

-- insert some data into it
insert into @mytemptable
select id, code from sourcetable

-- view the data
select * from @mytemptable
</pre>
<p><strong>How Long are Temporary Tables Good For:</strong><br />
Temporary tables are good for the length of your database session. If you have a query window in management studio, once you create a temporary table, it is available until you close that query window. You can also use the &#8216;drop table&#8217; statement on it.</p>
<p><strong>What are Temporary Tables Good For:</strong><br />
 &#8211; If you are analyzing data, it helps to store the results of frequently or long running sql<br />
 &#8211; If you are doing complex sql or aggregation (like or data warehouses), it might make your process simpler. I would use table variables (method 3) in that case, for performance reasons.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pressthered.com/creating_temporary_tables_in_sql_server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Include Column Headers in SQL Results</title>
		<link>http://www.pressthered.com/include_column_headers_in_sql_results/</link>
		<comments>http://www.pressthered.com/include_column_headers_in_sql_results/#comments</comments>
		<pubDate>Fri, 10 Jul 2009 06:21:25 +0000</pubDate>
		<dc:creator>jim.richmond</dc:creator>
				<category><![CDATA[Tech Tips]]></category>
		<category><![CDATA[microsoft sql server]]></category>

		<guid isPermaLink="false">http://www.pressthered.com/?p=515</guid>
		<description><![CDATA[To include column headers when pasting or saving sql results in Microsoft SQL Server Management Studio you must make a change on the Options Panel:

Open the Options panel in the menu bar
Navigate to Query Results -> SQL Server -> Results to Grid
Check &#8220;Include column headers when copying or saving the results.&#8221;

This works for SQL Server [...]]]></description>
			<content:encoded><![CDATA[<p>To include column headers when pasting or saving sql results in Microsoft SQL Server Management Studio you must make a change on the Options Panel:</p>
<ul>
<li>Open the Options panel in the menu bar</li>
<li>Navigate to Query Results -> SQL Server -> Results to Grid</li>
<li>Check &#8220;Include column headers when copying or saving the results.&#8221;</li>
</ul>
<div id="attachment_518" class="wp-caption aligncenter" style="width: 310px"><img src="http://www.pressthered.com/wp-content/uploads/2009/07/SQLOptions-300x177.jpg" alt="SQL Server Manangement Studio Options" title="SQL Server Manangement Studio Options" width="300" height="177" class="size-medium wp-image-518" /><p class="wp-caption-text">SQL Server Manangement Studio Options</p></div>
<p>This works for SQL Server 2005/2008. In SQL Server 2000&#8217;s Query Analyzer there was a button in the tool bar that turned on this option.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pressthered.com/include_column_headers_in_sql_results/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GUID Primary Keys in SQL</title>
		<link>http://www.pressthered.com/guid_primary_keys_in_sql/</link>
		<comments>http://www.pressthered.com/guid_primary_keys_in_sql/#comments</comments>
		<pubDate>Fri, 19 Jun 2009 05:41:22 +0000</pubDate>
		<dc:creator>jim.richmond</dc:creator>
				<category><![CDATA[Tech Tips]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[microsoft sql server]]></category>
		<category><![CDATA[mySQL]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.pressthered.com/?p=258</guid>
		<description><![CDATA[Creating a GUID in Microsoft SQL Server:

select newid();

Creating a GUID in MYSQL:

select uuid();

Why use a GUID as a primary key?
The main reason is if you want to guarantee uniqueness between databases and servers. 
I have never been a fan of GUIDs. Especially when having to write sql statements for reports. They&#8217;re difficult to scan and [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Creating a GUID in Microsoft SQL Server:</strong></p>
<pre name="code" class="sql">
select newid();
</pre>
<p><strong>Creating a GUID in MYSQL:</strong></p>
<pre name="code" class="sql">
select uuid();
</pre>
<p><strong>Why use a GUID as a primary key?</strong><br />
The main reason is if you want to guarantee uniqueness between databases and servers. </p>
<p>I have never been a fan of GUIDs. Especially when having to write sql statements for reports. They&#8217;re difficult to scan and impossible to sort. It used to be they were non existent and then they gained popularity when trying to store objects in relational databases became a fad. Try writing reports against an object hierarchy that is stored in a relational database. Every other column is a GUID. It&#8217;s not fun. </p>
<p>Anyway I had one recent experience that reinforced the need of a GUID in a database. Some production data was unintentionally lost in one table(due to a roll back). This particular table was using GUID&#8217;s as a primary key. The table could not be restored since it was already out of date. Instead the table was restored to a copy of the database. This allowed a quick comparison of the two tables and a painless insert via sql. What the GUID did in this case, was guarantee sameness (instead of uniqueness). </p>
<p>I am still going to stick to integers as primary keys but I am now going to add an auto generated GUID column for the sake of backup/restores/import/exports/etc.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pressthered.com/guid_primary_keys_in_sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
