<?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>JT Dev &#187; databases</title>
	<atom:link href="http://www.jtict.com/blog/tag/databases/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jtict.com/blog</link>
	<description>About programming stuff</description>
	<lastBuildDate>Sun, 11 Jul 2010 14:23:16 +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>Microsoft Access and informative id keys</title>
		<link>http://www.jtict.com/blog/access-informative-ids/</link>
		<comments>http://www.jtict.com/blog/access-informative-ids/#comments</comments>
		<pubDate>Thu, 17 Jul 2008 17:19:26 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[databases]]></category>
		<category><![CDATA[access2007]]></category>

		<guid isPermaLink="false">http://www.jtict.com/blog/?p=13</guid>
		<description><![CDATA[(Programmers usually don&#8217;t use Microsoft Access in multi user apps, but it can be handy if you quickly need to setup some single user personal administration database.)
A thing that I find very cumbersome in Access, is the use of surrogate keys (e.g. autonumbering IDs instead of business keys like &#8220;name&#8221;), because autonumbering keys are not [...]]]></description>
			<content:encoded><![CDATA[<p><strong>(Programmers usually don&#8217;t use Microsoft Access in multi user apps, but it can be handy if you quickly need to setup some single user personal administration database.)</strong></p>
<p><strong>A thing that I find very cumbersome in Access, is the use of surrogate keys (e.g. autonumbering IDs instead of business keys like &#8220;name&#8221;), because autonumbering keys are not very informative. This blog post tells you how you can show informative field while at the same time keep using your existing surrogate keys.</strong></p>
<p>Tested with Microsoft Access 2007.</p>
<h3>Example of the problem</h3>
<p>Here an example of the problem: you have a STUDENT table and a COLLEGE table, where a student has only one college, and a college can have multiple students. (A one-to-many relation.)</p>
<p><img class="aligncenter size-full wp-image-15" title="relationship" src="http://www.jtict.com/blog/wp-content/uploads/2008/07/relationship.png" alt="" width="441" height="149" /></p>
<p><img class="aligncenter size-full wp-image-14" title="college-data" src="http://www.jtict.com/blog/wp-content/uploads/2008/07/college-data.png" alt="" width="314" height="122" /></p>
<p><img class="aligncenter size-full wp-image-21" title="student-data" src="http://www.jtict.com/blog/wp-content/uploads/2008/07/student-data.png" alt="" width="309" height="125" /></p>
<p>Now when you want to select/assign a college to a student, you don&#8217;t want to select it using <strong>NON-informative</strong> college_id&#8217;s like this:</p>
<p><img class="aligncenter size-full wp-image-16" title="select-college-id" src="http://www.jtict.com/blog/wp-content/uploads/2008/07/select-college-id.png" alt="" width="329" height="146" /></p>
<p>instead you want select college_id&#8217;s using <strong>informative</strong> college names like :</p>
<p><img class="aligncenter size-full wp-image-17" title="select-college-id-informative" src="http://www.jtict.com/blog/wp-content/uploads/2008/07/select-college-id-informative.png" alt="" width="415" height="137" /></p>
<p>And after after selecting the college_id, you want the informative college fields to stay visible in the list, like this:<br />
<img class="aligncenter size-full wp-image-19" title="show-college-id-informative" src="http://www.jtict.com/blog/wp-content/uploads/2008/07/show-college-id-informative.png" alt="" width="423" height="159" /></p>
<p>while at the same time having a transparant relationship using the numbered surrogate id&#8217;s as foreign keys.</p>
<h3>Composed of two subproblems</h3>
<p>The problem consists of two sub problems:</p>
<ol>
<li>selecting non-informative foreign key id&#8217;s transparently using informative fields.</li>
<li>showing (single or multiple) informative fields in the list instead of a non-informative foreign id key</li>
</ol>
<h3>Solution using Lookup Wizard</h3>
<p>The easiest way to accomplish this is to use the &#8220;Lookup Wizard&#8221;. This wizard creates a (new) relationship between the 2 tables, so you have to make sure that a relation doesn&#8217;t exist yet.<br />
In this case, college_id will be the foreign key and thus the lookup column.</p>
<p>There are two ways to access the Lookup Wizard:</p>
<ol>
<li>via the &#8220;Lookup Column&#8221; button. This creates a new column, so college_id shoudn&#8217;t exist yet. Or</li>
<li>by selecting &#8220;Lookup Wizard&#8221; as &#8220;Data Type&#8221; for college_id.</li>
</ol>
<p>The wizard is self-explanatory. When selecting the column in this wizard, make sure you select BOTH the id, AND the columns that you want to be visible. You also have an option to hide the ID, which can be enabled if you prefer.</p>
<p>After finishing the wizard, you&#8217;ll see that you can now use informative fields instead of non-informative id&#8217;s, while transparently maintaining a foreign key relation using the non-informative id&#8217;s.</p>
<h3>Manual solution</h3>
<p>If you don&#8217;t to use the Lookup wizards, you can do it manually yourself in the field properties of college_id:</p>
<ol>
<li>change the &#8220;Display Control&#8221; to &#8220;List Box&#8221; or &#8220;Combo Box&#8221;</li>
<li>set &#8220;Row Source Type&#8221; to &#8220;Table/Query&#8221;</li>
<li>set &#8220;Row Source&#8221; to a query that contain BOTH the foreign key (college_id) AND the data that you want to be visible as value (cname in this case). The id column MUST be the first column, even if you don&#8217;t want it to be visible.</li>
<li>set &#8220;Column Count&#8221; to the number of columns of the query from step 3</li>
<li>set &#8220;Column Widths&#8221; for the columns. The ugly part: it is important that you set 0 as width for the id, so that it will be skipped and not be visible in the row, and thus the second column will be visible, which is our informative column.</li>
</ol>
<h3>Multiple informative field in the list</h3>
<p>The text above only partially solves subproblem 2; it shows ONLY 1 informative field, even when you selected multiple informative field in the wizard.<br />
For example, it shows</p>
<p><img class="aligncenter size-full wp-image-18" title="select-multiple" src="http://www.jtict.com/blog/wp-content/uploads/2008/07/select-multiple.png" alt="" width="403" height="151" /></p>
<p>where only &#8220;MyFirstCollege&#8221; is visible instead of also the value &#8220;Rotterdam&#8221;. Instead we want:</p>
<p><img class="aligncenter size-full wp-image-20" title="show-multiple" src="http://www.jtict.com/blog/wp-content/uploads/2008/07/show-multiple.png" alt="" width="464" height="166" /></p>
<p>where the &#8220;location&#8221; field of the COLLEGE table is also visible.</p>
<p>A manual solution to show multiple informative field in a row (like the last picture), is to concatenate the fields. This can be done by going to the field properties of college_id in the STUDENT table, and alter the SQL query:<br />
SELECT COLLEGE.ID, COLLEGE.cname, COLLEGE.location FROM COLLEGE;<br />
to<br />
SELECT COLLEGE.ID, COLLEGE.cname &amp; &#8216;-&#8217; &amp; COLLEGE.location FROM COLLEGE;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jtict.com/blog/access-informative-ids/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
