<?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>Webdevotion.be &#187; Coldfusion</title>
	<atom:link href="http://www.webdevotion.be/blog/category/coldfusion/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.webdevotion.be/blog</link>
	<description>Trainer for the Flash Platform and iOS</description>
	<lastBuildDate>Tue, 01 Nov 2011 10:14:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>The story of compound keys</title>
		<link>http://www.webdevotion.be/blog/2007/09/28/the-story-of-compound-keys/</link>
		<comments>http://www.webdevotion.be/blog/2007/09/28/the-story-of-compound-keys/#comments</comments>
		<pubDate>Fri, 28 Sep 2007 09:37:05 +0000</pubDate>
		<dc:creator>Webdevotion</dc:creator>
				<category><![CDATA[Coldfusion]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Ruby On Rails]]></category>

		<guid isPermaLink="false">http://webdevotion.be/blog/?p=17</guid>
		<description><![CDATA[Short story: I needed a table that could visualize the relation between two other tables ( services &#038; portfolio ). So I set up a &#8220;join table&#8221;; a table that has two columns: service_id and portfolio_id. Each column contains a &#8230; <a href="http://www.webdevotion.be/blog/2007/09/28/the-story-of-compound-keys/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Short story: I needed a table that could visualize the relation between two other tables ( services &#038; portfolio ).  So I set up a &#8220;join table&#8221;; a table that has two columns: service_id and portfolio_id.  Each column contains a foreign key ( services.id and portfolio.id ).</p>
<p>Now, what you normally do is add a third column &#8220;id&#8221; as primary key.  But in this case it can be a recipe for ( a programmer&#8217;s ) disaster. The column id would always contain a unique value, but the combination of the two other columns service_id and portfolio_id will not be unique.  And thus you could run into a situation where you have multiple rows that hold the same relation:</p>
<p><span id="more-17"></span><br />
<code><br />
id   |   service_id   | portfolio_id<br />
-------------------------------<br />
1    |         5        |       3<br />
2    |         2        |       1<br />
3    |         5        |       3<br />
</code></p>
<p>The solution is the use of a compound key: use only two columns and make them both primary key.  This will force the relation to be unique, always.  </p>
<p><code><br />
  service_id  | portfolio_id<br />
--------------------------<br />
        5        |       3<br />
        2        |       1<br />
</code></p>
<p>I&#8217;m suprised I never had to use this before, but I remembered a reference in the &#8220;Agile Development with Rails&#8221; book.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webdevotion.be/blog/2007/09/28/the-story-of-compound-keys/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

