<?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>Geekgirl&#039;s Plain English Computing &#187; Databases</title>
	<atom:link href="http://www.geekgirls.com/category/office/databases/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.geekgirls.com</link>
	<description>Tutorials and commentary on all things Windows &#38; web, with a few tangential offerings.</description>
	<lastBuildDate>Mon, 31 Oct 2011 12:17:56 +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>Databasics VII: Parameter Queries</title>
		<link>http://www.geekgirls.com/2011/09/databasics-vii-parameter-queries/</link>
		<comments>http://www.geekgirls.com/2011/09/databasics-vii-parameter-queries/#comments</comments>
		<pubDate>Thu, 29 Sep 2011 23:49:28 +0000</pubDate>
		<dc:creator>rosevines</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Office Apps]]></category>
		<category><![CDATA[database design]]></category>
		<category><![CDATA[database queries]]></category>
		<category><![CDATA[dbms]]></category>
		<category><![CDATA[microsoft access]]></category>
		<category><![CDATA[queries]]></category>

		<guid isPermaLink="false">http://www.geekgirls.com/?p=1399</guid>
		<description><![CDATA[Interactive, on-the-fly parameter queries add a huge amount of flexibility and power to run-of-the-mill static queries. Learn how to create your own using Microsoft Access.]]></description>
			<content:encoded><![CDATA[<div class="woo-sc-box info   full">Note: I&#8217;m working on updating this series of articles. This article is really showing its age. All the examples are for  Microsoft Access 2000/2003, and things have changed a lot since then. While the concepts are still the same and you can learn a lot from those, the step-by-steps are quite different if you&#8217;re working with a newer database program such as Access 2007 or 2010. I plan to produce a new article with Access 2010 examples in the next month or so, so if you&#8217;re interested, check back in a while.</div>
<p><span class="dropcap">I</span><!--/.dropcap-->f the title of this tutorial sounds a little intimidating, never fear. Toss the term &#8216;parameter query&#8217; around at a party and you may get a few gasps of admiration, but understanding and using this highly useful type of query is no big deal.</p>
<p>A parameter query is interactive – it prompts the user for information when it&#8217;s run. You can use a parameter query to ask the user for criteria for retrieving records or for a particular value to insert in a field. This makes parameter queries great for generating dynamic, on-the-fly results.</p>
<p>If you think of the queries we&#8217;ve examined in earlier articles in this series, while the data may change, the query itself is static:</p>
<ul>
<li>Which countries have a population over 20 million and an area of over 2 million square kilometres?</li>
<li>Which country has the smallest population density?</li>
</ul>
<p>With parameter queries, both the data and the queries may change over time:</p>
<ul>
<li>Which countries have a population between x and y?</li>
<li>Which countries joined the United Nations in the nth decade of 2000?</li>
</ul>
<p>You obtain the values for those variables – x, y and n – by asking the user to supply them each time the query is run.</p>
<h2>Creating a parameter query</h2>
<p>Let&#8217;s take a look at some parameter queries in action, using Microsoft Access, which provides tools that let us do this job easily. We&#8217;ll use the Countries database we&#8217;ve used previously (you&#8217;ll find a download link at the bottom of this page) and start by creating a non-parameter query to answer the question &#8220;Which countries have a population greater than one hundred million?&#8221; We&#8217;ll then transform that query into a parameter query and contrast the results.</p>
<p>Here goes:</p>
<ol>
<li>Open the Countries database in Access.</li>
<li>In the main Database Window, click Queries in the Objects list.</li>
<li>Double-click Create Query In Design View to open the Query window and Show Table box.</li>
<li>Select the Countries table to add it to the Query window, click Add, and then click Close.</li>
<li>Click Name in the list of fields, hold down the Ctrl key and click Population. Drag the two fields to the left-hand column in the query design grid to add the fields to the query.</li>
<li>In the Population column in the grid, type:</li>
</ol>
<blockquote><p><strong>&gt;100000000</strong></p>
<p>in the Criteria row.</p></blockquote>
<ol start="7">
<li>Click the Run button (it has an exclamation mark on it) to run the query. You should see 11 countries listed, each with a population greater than 100 million.</li>
</ol>
<p>That&#8217;s our simple, non-parameter query, which we created by providing a constant (100 million) as the matching criteria. Now let&#8217;s change it into a more flexible parameter query, which uses variables provided by the user instead of a constant.</p>
<ol>
<li>Click the View button (it&#8217;s the left-most button on the toolbar) to return to Design View, so we can modify the query.</li>
<li>Delete the contents of the Criteria cell in the Population column and replace it with:</li>
</ol>
<blockquote><p><strong>&gt;[Show countries with a population over:]</strong></p>
<p>You may need to resize the column (by dragging the right edge of the column header to the right) so you can see the entire contents.</p></blockquote>
<ol start="3">
<li>Click the Run button. You&#8217;ll be presented with a dialog box containing the prompt, &#8220;Show countries with a population over:&#8221; Fill in any value you like and click OK to see the results.</li>
<li>Save this query by clicking the Save button and naming it <em>Population over x</em>.</li>
</ol>
<h2>Parameter tips</h2>
<p>Neat, huh? Let&#8217;s examine the query to see how we did this.</p>
<p>The criteria consists of the greater than operator (&gt;) followed by the prompt we wish to use enclosed in square brackets:</p>
<p><strong>&gt;[Show countries with a population over:]</strong></p>
<p>That&#8217;s simple enough, but there are two important things to keep in mind when you create your parameter prompts. First, be succinct. Access lops the prompt off at 37 characters, so if you are verbose you&#8217;ll end up with shabby-looking, truncated prompts.</p>
<p>Second, be as clear as possible. Although you want to be succinct, don&#8217;t become cryptic. For instance, you could just as easily use the criteria:</p>
<p><strong>&gt;[Pop greater than:]</strong></p>
<p>or even</p>
<p><strong>&gt;[Pop?]</strong></p>
<p>Those will work, but if someone else tries to use your database or you use the query only occasionally, a more informative prompt will avoid confusion and ensure the correct input.</p>
<h2>Obtaining a range</h2>
<p>Your parameter queries are not restricted to a single prompt. You can use them to find a range of values or obtain multiple criteria.</p>
<p>Here&#8217;s a query which answers the question, &#8220;Which countries have a population between x and y?&#8221; by prompting for a lower and an upper value:</p>
<p>1. If you still have the results of the <em>Population over X</em> query open, click the View button to return to Design View. If you closed the query after saving it, highlight it in the Queries list and click Design to open it in Design View.</p>
<p>2. In the Criteria cell of the Population column, add:</p>
<p><strong>AND &lt;[and a population under:]</strong></p>
<p>The full criterion should now read:</p>
<p><strong>&gt;[Show countries with a population over:] AND &lt;[and a population under:]</strong></p>
<p>3. Run the query and you&#8217;ll be prompted twice. Enter a lower limit in the first dialog and an upper limit in the second, then click OK to see the results.</p>
<p>4. From the File Menu choose Save As and name the query <em>Population Range</em>. By saving the query, you&#8217;ll be able to run it repeatedly, supplying different values each time.</p>
<p>This range query is similar to queries we&#8217;ve explored before, using two comparison operators (&gt; and &lt;) and the logical operator AND, but instead of using constant values, it substitutes two parameters obtained via dialogs.</p>
<h2>A range example using dates</h2>
<p>Let&#8217;s try one more range parameter query, this time using dates. This one will answer questions such as &#8220;Which countries joined the United Nations in the nth decade of 2000?&#8221;</p>
<ol>
<li>Create a new query in Design View.</li>
<li>Select the Countries table and click Add to add it to the query, then close the Show Tables dialog.</li>
<li>Drag the fields Name and JoinedUN onto the query grid.</li>
<li>In the Criteria cell of the JoinedUN column, type:</li>
</ol>
<blockquote><p><strong>&gt;[Joined UN after what date:] And &lt;[and before what date:]</strong></p></blockquote>
<ol start="5">
<li>Run this query and respond to the prompts by typing dates in the format dd/mm/yyyy. To view all countries that joined the United Nations during the nineties, for instance, enter the values <em>31/12/1989</em> and <em>1/1/2001</em>. If you use mm/dd format instead of dd/mm format for dates, you&#8217;ll want to make that first value 12/31/1989, of course.</li>
<li>Save this query and name it <em>Date Range</em>.</li>
</ol>
<p>You can, of course, use other operators (&lt;&gt;, =, &lt;= and so on) and logical expressions (OR, NOT) in range queries.</p>
<h2>Multiple values</h2>
<p>As well as matching a range of values in a single field, you can use parameter queries to match values in more than one field.</p>
<p>Let&#8217;s modify the Date Range query to let us not only specify a date range, but also limit the answer to countries over a certain population.</p>
<ol>
<li>Open the Date Range query in Design View.</li>
<li>Drag the Population field from the field list onto the query design grid to the right of the JoinedUN field. Our query now contains three fields – Name, JoinedUN and Population.</li>
<li>In the Criteria cell of the Population column, type:</li>
</ol>
<blockquote><p><strong>&gt;[and has a population over:]</strong></p></blockquote>
<ol start="4">
<li>Run the query.</li>
</ol>
<p>You&#8217;ll be presented with three prompts, asking for lower and upper dates and then a lower population limit. Note that this query in essence uses the AND logical operator to extend the query, so it&#8217;s the equivalent of: Show me countries that joined the UN between date x AND date y AND which have a population over n.</p>
<div id="attachment_1401" class="wp-caption alignnone" style="width: 622px"><a href="http://www.geekgirls.com/wp-content/uploads/running_a_parameter_query.jpg"><img class="size-full wp-image-1401" title="Running a parameter query" src="http://www.geekgirls.com/wp-content/uploads/running_a_parameter_query.jpg" alt="Running a parameter query" width="612" height="814" /></a><p class="wp-caption-text">Running a parameter query: A parameter query prompts the user for one or more criteria. In this example, the user specifies a population range and the query returns all matching records.</p></div>
<h2>Avoiding endless dialogs</h2>
<p>Try experimenting with parameter queries on your own. You&#8217;ll find they add enormous flexibility to the types of information you can wheedle out of your database. A tourist bureau, for example, can use them to provide information to the public on local events occurring this week. A small business can find all those customers who placed orders over a specific amount in the previous quarter. You&#8217;re sure to come up with instances where you can use them with your own data.</p>
<p>The only drawback with these queries is that you can end up peppering your users with endless, rather unattractive prompt boxes as you try to collect all the necessary parameters.</p>
<p>There&#8217;s good news. With a little fast footwork, you can avoid these dialogs and replace them with a single, good-looking dialog of your own design. I&#8217;ll show you how in the next article in this series.</p>
<p>Related posts:<ol>
<li><a href='http://www.geekgirls.com/2011/09/databasics-vi-exploring-query-types/' rel='bookmark' title='Databasics VI: Exploring query types'>Databasics VI: Exploring query types</a></li>
<li><a href='http://www.geekgirls.com/2011/09/databasics-v-getting-information-out/' rel='bookmark' title='Databasics V: Getting information out'>Databasics V: Getting information out</a></li>
<li><a href='http://www.geekgirls.com/2010/02/databasics-i-records-queries-keys-oh-my/' rel='bookmark' title='Databasics I: Records &amp; queries &amp; keys, oh my!'>Databasics I: Records &#038; queries &#038; keys, oh my!</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.geekgirls.com/2011/09/databasics-vii-parameter-queries/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Databasics VI: Exploring query types</title>
		<link>http://www.geekgirls.com/2011/09/databasics-vi-exploring-query-types/</link>
		<comments>http://www.geekgirls.com/2011/09/databasics-vi-exploring-query-types/#comments</comments>
		<pubDate>Thu, 29 Sep 2011 23:35:46 +0000</pubDate>
		<dc:creator>rosevines</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[Office Apps]]></category>
		<category><![CDATA[action queries]]></category>
		<category><![CDATA[calculated fields]]></category>
		<category><![CDATA[data access]]></category>
		<category><![CDATA[database design]]></category>
		<category><![CDATA[database queries]]></category>
		<category><![CDATA[dbms]]></category>
		<category><![CDATA[microsoft access]]></category>
		<category><![CDATA[parameter queries]]></category>
		<category><![CDATA[queries]]></category>
		<category><![CDATA[select queries]]></category>

		<guid isPermaLink="false">http://www.geekgirls.com/?p=1386</guid>
		<description><![CDATA[Learn how to start building more complex database queries, such as comparative and action queries, using Microsoft Access.
   ]]></description>
			<content:encoded><![CDATA[<div class="woo-sc-box info   full">Note: I&#8217;m working on updating this series of articles. This article is really showing its age. All the examples are for  Microsoft Access 2000/2003, and things have changed a lot since then. While the concepts are still the same and you can learn a lot from those, the step-by-steps are quite different if you&#8217;re working with a newer database program such as Access 2007 or 2010. I plan to produce a new article with Access 2010 examples in the next month or so, so if you&#8217;re interested, check back in a while.</div>
<p><span class="dropcap">I</span><!--/.dropcap-->n the previous tutorial we used Query By Example (QBE) on a database of countries to answer questions such as &#8216;Which countries are members of the UN Security Council?&#8217; and &#8216;Which countries have a population over 20 million and an area over 2 million square kilometres?&#8217; These are simple queries which we created using QBE and basic operators such as &gt; (greater than).</p>
<p>It&#8217;s possible to ask more complex questions, such as:</p>
<ul>
<li>Which country joined the UN most recently?</li>
<li>Which countries are in the top 5% in terms of area?</li>
<li>Which five countries have the lowest population density?</li>
</ul>
<p>The way you tackle these queries depends on which database program you use. I&#8217;ll be using Microsoft Access in the examples, as it has querying tools that leave most other PC databases in the shade. You can download <a href="http://www.box.net/shared/xz73meuimr9yqgcgqods" target="_blank">a sample copy of the database</a> to try this out for yourself.</p>
<p><strong>Comparative queries</strong></p>
<p>The simple queries we explored last time did nothing more than find a matching value (Name=Namibia), or compare a value in a field to a constant (Population&lt;=20000000).</p>
<p>We can take this a step further and run queries that will compare one piece of data against the rest of the data in the table. These are real bread-and-butter queries. For instance, in a sales database, you might want the answers to questions such as: Which region had the lowest sales for the quarter? Who are our five best salespeople? Which salespeople performed better this quarter than last?</p>
<p>To ask these types of questions, you need to use something a little more sophisticated than QBE. In Access, you use the Query Designer.</p>
<p><strong>Using Access&#8217;s Query Designer</strong></p>
<p>Let&#8217;s start with the question, Which country joined the UN most recently? Here&#8217;s how to get the answer:</p>
<ol start="1">
<li>Open the Countries database in Access.</li>
<li>In the main Database Window, click Queries in the Objects list.</li>
<li>Double-click Create Query In Design View. A Query window opens together with a Show Table box containing all the tables in our database.</li>
<li>Select the Countries table, click Add, and then click Close. This adds the Countries database to the Query window, so we can work with it.</li>
<li>Click Name in the list of fields and then hold down the Ctrl key and click JoinedUN (you may need to scroll to see it). Drag the two fields to the left-hand column in the query design grid. The two fields will appear side by side in the grid. The top row in the grid shows the field name; the second row shows which table the field belongs to (we&#8217;ll get into multi-table queries at a later date); the third row lets you specify a sort order for the results; the fourth row (Show) specifies whether you want the contents of this field displayed in the results; the fifth and sixth rows specify criteria for selecting records.</li>
<li>In the JoinedUN column on the grid, click in the Sort row and, from the drop-down box, select Descending. This tells Access we want the table sorted with the most recent records (those with the&#8217;largest&#8217; dates) first.</li>
<li>In the toolbar, beside the Sigma button you&#8217;ll see an empty drop-down box. This is the Top Values button. Type 1 in this box. We&#8217;re looking for the &#8216;top date&#8217;, so to speak – the most recent date in the JoinedUN field – so we want the top, single value.</li>
<li>Run the query by clicking the Run button (it has an exclamation mark on it). You&#8217;ll see the result is Tuvalu, which joined the UN on the 5th September, 2000.</li>
</ol>
<blockquote><p><strong><div class="woo-sc-box normal   ">geekgirl:geopolitical update</strong></p>
<p>In fact, if you run this query on the updated version of the Countries database I now have online, you&#8217;ll find the answer is not Tuvalu, but South Sudan. East Timor, Switzerland, Montenegro and South Sudan have all joined the United Nations since I first wrote this article. While I&#8217;ve left the article text the same, I have updated the database to reflect these recent additions to the United Nations family (I haven&#8217;t had a chance to update the population figures, alas).</p>
<p>These changes show how useful database queries can be: Provided the data in your database is accurate and up to date, you can use a query you created years ago on your current data and get an accurate and up-to-date result.</div></p></blockquote>
<p><strong>Saving and re-running queries</strong></p>
<p>Click the Close box on the Query window. You&#8217;ll be asked whether you want to save the query. Click Yes, name the query <em>Most Recent Member</em> and click OK.</p>
<p>Why should you save a query? After all, you already know the answer to your question is Tuvalu. But then, the answer won&#8217;t always be Tuvalu. Say Switzerland decides to join the UN this year, or a new country emerges from one of the bubbling spots on the globe and becomes a new member? (See the Geopolitical Update above.)</p>
<p>By saving the query, you can re-run it at any time and find the up-to-date answer to your question. This may seem a fairly trivial operation with our simple example, but when you&#8217;re creating complex queries or, more importantly, when your data changes regularly, saved queries eliminate a lot of work.</p>
<p>To use your saved query, simply double-click it in the Queries list.</p>
<p><strong>Query types</strong></p>
<p>The Most Recent Member query you created is called a Select query. Access lets you create five different types of query:</p>
<p><strong>Select queries.</strong> Used to retrieve data from one or more tables and display the results in a datasheet, which you can save or modify. You can also use Select queries to group records and calculate sums, averages and so on.</p>
<p><strong>Parameter queries.</strong> For creating on-the-fly queries which prompt the user for criteria at the time the query is run. For example, you can create a parameter query that answers the question: Which countries have a population greater than X and less than Y? Each time you run the query, it will prompt you for the values of X and Y. Thus you can use the same query repeatedly to discover different information.</p>
<p><strong>Crosstab queries.</strong> Used to summarise data from one field and group it in tabular fashion according to two criteria.</p>
<p><strong>Action queries.</strong> Queries that make changes to the records in a table. There are four type of action queries: <em>Delete queries</em> remove records from a table; <em>Update queries</em> make global changes to a group of records in a table; <em>Append queries</em> add records from one or more tables to the end or one or more tables; <em>Make-table queries</em> create a new table from all or part of the data in an existing table.</p>
<p><strong>SQL queries.</strong> A query created using SQL, which is a highly advanced querying language. SQL queries give you enormous flexibility, but require a high degree of expertise to use effectively.</p>
<p><strong>A select query example</strong></p>
<p>Let&#8217;s quickly run through a second select query, answering the question: Which countries are in the top 5% in terms of area?</p>
<ol start="1">
<li>Double-click Create Query In Design View.</li>
<li>Select the Countries table, click Add, and then click Close.</li>
<li>Click Name in the list of fields, Ctrl-click Area, and drag the two fields to the grid.</li>
<li>In the Area column, choose Descending from the Sort drop-down box.</li>
<li>In the Top Values box on the toolbar, type 5% (or select it from the drop-down list).</li>
<li>Click Run to execute the query.</li>
</ol>
<p><strong>Calculated fields</strong></p>
<p>How about the question: Which five countries have the lowest population density? We don&#8217;t have a Population Density field in our table, so how can we calculate it?</p>
<p>We do it by creating a new field which becomes part of our results (note, though, that the field does not become part of the existing table structure). Here&#8217;s how:</p>
<ol start="1">
<li>Double-click Create Query In Design View.</li>
<li>Select the Countries table, click Add, and then click Close.</li>
<li>Drag the Name and Population fields onto the grid.</li>
<li>In the top row of the empty third column on the grid, type:</li>
</ol>
<p>PopDensity: population/area</p>
<p>and press Enter. We&#8217;re creating a new column (PopDensity) whose values will be calculated by dividing each country&#8217;s population by its area. By the way, if you can&#8217;t see the entire contents of this column, drag the right-hand edge of the column header to the right to resize it.</p>
<ol start="5">
<li>In the Top Values box on the toolbar, type 5.</li>
<li>Click the Totals button (it has the Sigma sign on it). A new Totals row appears in the grid.</li>
<li>In the PopDensity column choose Ascending from the Sort box.</li>
<li>Click Run to execute the query.</li>
</ol>
<p>The results show the names, population and population density for the world&#8217;s least populated countries.</p>
<div id="attachment_1390" class="wp-caption alignnone" style="width: 621px"><a href="http://www.geekgirls.com/wp-content/uploads/calculated_query.jpg"><img class="size-full wp-image-1390  " title="A select query" src="http://www.geekgirls.com/wp-content/uploads/calculated_query.jpg" alt="A select query" width="611" height="387" /></a><p class="wp-caption-text">This Select query in Access finds the five most sparsely populated countries in the world using a calculated field, PopDen</p></div>
<p>&nbsp;</p>
<p><strong>An action query</strong></p>
<p>Let&#8217;s finish up by converting that last query into an action query. This query doesn&#8217;t merely provide us with the results; it saves them in a new table which includes a PopDensity field in its structure. The original table remains intact and unchanged; it&#8217;s the new results table which has the extended structure.</p>
<ol start="1">
<li>If you have the query results still showing, click the View button at the left end of the toolbar to view the query in design mode once more. If you have already closed the query, recreate it.</li>
<li>Click the down arrow on the Query Type button on the toolbar and select Make-Table Query.</li>
<li>Name the query <em>Sparsely Populated</em>, leave the Current Database option selected, and click OK.</li>
<li>Run the query and, when prompted, say Yes to create the new table.</li>
<li>Close the query, click Tables in the Objects panel, and you&#8217;ll see a new table called Sparsely Populated. Double-click it to see the query results in the new table. You&#8217;ll notice the new table contains five records (the most sparsely populated five countries) and three fields – Name, Population and PopDensity.</li>
</ol>
<p>&nbsp;</p>
<p>Related posts:<ol>
<li><a href='http://www.geekgirls.com/2011/09/databasics-vii-parameter-queries/' rel='bookmark' title='Databasics VII: Parameter Queries'>Databasics VII: Parameter Queries</a></li>
<li><a href='http://www.geekgirls.com/2011/09/databasics-v-getting-information-out/' rel='bookmark' title='Databasics V: Getting information out'>Databasics V: Getting information out</a></li>
<li><a href='http://www.geekgirls.com/2010/02/databasics-i-records-queries-keys-oh-my/' rel='bookmark' title='Databasics I: Records &amp; queries &amp; keys, oh my!'>Databasics I: Records &#038; queries &#038; keys, oh my!</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.geekgirls.com/2011/09/databasics-vi-exploring-query-types/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Which database series should I read?</title>
		<link>http://www.geekgirls.com/2011/09/which-database-series-should-i-read/</link>
		<comments>http://www.geekgirls.com/2011/09/which-database-series-should-i-read/#comments</comments>
		<pubDate>Tue, 27 Sep 2011 22:41:27 +0000</pubDate>
		<dc:creator>rosevines</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Office Apps]]></category>

		<guid isPermaLink="false">http://www.geekgirls.com/?p=1363</guid>
		<description><![CDATA[Not sure which series of database tutorials on Geekgirl's Plain English Computing is right for you, Databasics or Databases from Scratch? Here's a quick description of their contents.]]></description>
			<content:encoded><![CDATA[<p><span class="dropcap">I</span><!--/.dropcap-->n the beginning there was a single series of database tutorials on this site. Now there are two. Which one should you read?</p>
<p>If you&#8217;re looking for a nice, slow approach to learning databases, choose <em>Databasics.</em> It will help you learn the lingo, start with simple stuff, and eventually take on something a little more challenging. It&#8217;s a series in development, so you can munch on some new information, go away and put it to use, then come back in a month or so and try something new. It&#8217;s also a very practical series. In Databasics, although the techniques and general advice apply no matter which database product you use, you&#8217;ll find specific advanced examples feature Microsoft Access.</p>
<p>If, on the other hand, you want to dive right into the nitty gritty of database design, try the companion series of articles, <em>Databases from Scratch.</em> While there&#8217;s some overlap between the two series, <em>Databases from Scratch</em> moves onto advanced topics, such as relational database design, more rapidly and restricts its topic matter to design issues. <em>Databasics</em> wanders farther afield, and includes (or will eventually include) tutorials on queries, reports, forms design, application development as well as basic design principles. </p>
<p>Related posts:<ol>
<li><a href='http://www.geekgirls.com/2007/11/the-year-of-the-database/' rel='bookmark' title='The year of the database'>The year of the database</a></li>
<li><a href='http://www.geekgirls.com/2011/09/databases-from-scratch-ii-simple-database-design/' rel='bookmark' title='Databases from scratch II: Simple Database Design'>Databases from scratch II: Simple Database Design</a></li>
<li><a href='http://www.geekgirls.com/2010/02/a-database-dictionary/' rel='bookmark' title='A database dictionary'>A database dictionary</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.geekgirls.com/2011/09/which-database-series-should-i-read/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Databases from scratch III: The Design Process</title>
		<link>http://www.geekgirls.com/2011/09/databases-from-scratch-iii-relational-design-process/</link>
		<comments>http://www.geekgirls.com/2011/09/databases-from-scratch-iii-relational-design-process/#comments</comments>
		<pubDate>Tue, 27 Sep 2011 22:32:45 +0000</pubDate>
		<dc:creator>rosevines</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Office Apps]]></category>
		<category><![CDATA[database design]]></category>
		<category><![CDATA[dbms]]></category>
		<category><![CDATA[microsoft access]]></category>
		<category><![CDATA[relational database]]></category>
		<category><![CDATA[relational database design]]></category>

		<guid isPermaLink="false">http://www.geekgirls.com/?p=1348</guid>
		<description><![CDATA[This third article in the Databases from Scratch series delves into the database heartland by exploring relational database design.]]></description>
			<content:encoded><![CDATA[<p><em>This third article in the series delves into the database heartland by exploring relational database design.</em></p>
<p><span class="dropcap">O</span><!--/.dropcap-->ne of the best ways to understand the importance of good database design is to start with an all-in-one, flat-file table design and then toss in some sample data to see what happens. By analysing the sample data, you&#8217;ll be able to identify problems caused by the initial design. You can then modify the design to eliminate the problems, test some more sample data, check for problems, and re-modify, continuing this process until you have a consistent and problem-free design.</p>
<p>Once you grow accustomed to the types of problems poor table design can create, hopefully you&#8217;ll be able to skip the interim steps and jump immediately to the final table design.</p>
<h2>A sample design process</h2>
<p>Let&#8217;s step through a sample database design process.</p>
<p>We&#8217;ll design a database to keep track of students&#8217; sports activities. We&#8217;ll track each activity a student takes and the fee per semester to do that activity.</p>
<p><strong>Step 1: Create an Activities table</strong> containing all the fields: student&#8217;s name, activity and cost. Because some students take more than one activity, we&#8217;ll make allowances for that and include a second activity and cost field. So our structure will be: Student, Activity 1, Cost 1, Activity 2, Cost 2</p>
<p><strong>Step 2: Test the table with some sample data.</strong> When you create sample data, you should see what your table <em>lets you get away with.</em> For instance, nothing prevents us from entering the same name for different students, or different fees for the same activity, so do so. You should also imagine trying to ask questions about your data and getting answers back (essentially <em>querying</em> the data and producing reports). For example, how do I find all the students taking tennis?</p>
<p><strong>Step 3: Analyse the data. </strong>In this case, we can see a glaring problem in the first field. We have two John Smiths, and there&#8217;s no way to tell them apart. We need to find a way to identify each student uniquely.</p>
<p><a href="http://www.geekgirls.com/wp-content/uploads/activities_01.gif"><img class="alignnone size-full wp-image-1350" title="A flawed table design" src="http://www.geekgirls.com/wp-content/uploads/activities_01.gif" alt="A flawed table design" width="376" height="134" /></a></p>
<h2>Uniquely identify records</h2>
<p>Let&#8217;s fix the glaring problem first, then examine the new results.</p>
<p><strong>Step 4: Modify the design. </strong>We can identify each student uniquely by giving each one a unique ID, a new field that we add, called ID. We scrap the Student field and substitute an ID field. Note the asterisk (*) beside this field in the table below: it signals that the ID field is a <em>key field</em>, containing a unique value in each record. We can use that field to retrieve any specific record. When you create such a key field in a database program, the program will then prevent you from entering duplicate values in this field, safeguarding the uniqueness of each entry.</p>
<p>Our table structure is now: ID, Activity 1, Cost 1, Activity 2, Cost 2</p>
<p>While it&#8217;s easy for the computer to keep track of ID codes, it&#8217;s not so useful for humans. So we&#8217;re going to introduce a second table that lists each ID and the student it belongs to. Using a database program, we can create both table structures and then link them by the common field, ID. We&#8217;ve now turned our initial <em>flat-file</em> design into a <em>relational database</em>: a database containing multiple tables linked together by key fields. If you were using a database program that can&#8217;t handle relational databases, you&#8217;d basically be stuck with our first design and all its attendant problems. With a relational database program such as Microsoft Access or FileMaker, you can create as many tables as your data structure requires.</p>
<p>The Students table would normally contain each student&#8217;s first name, last name, address, age and other details, as well as the assigned ID. To keep things simple, we&#8217;ll restrict it to name and ID, and focus on the Activities table structure.</p>
<p><strong>Step 5: Test the table with sample data.</strong></p>
<p><a href="http://www.geekgirls.com/wp-content/uploads/activities_02.gif"><img class="alignnone size-full wp-image-1351" title="Splitting the flat file into two related tables" src="http://www.geekgirls.com/wp-content/uploads/activities_02.gif" alt="Splitting the flat file into two related tables" width="340" height="277" /></a></p>
<p><strong>Step 6: Analyse the data.</strong> There&#8217;s still a lot wrong with the Activities table:</p>
<ol>
<li>Wasted space. Some students don&#8217;t take a second activity, and so we&#8217;re wasting space when we store the data. It doesn&#8217;t seem much of a bother in this sample, but what if we&#8217;re dealing with thousands of records?</li>
<li>Addition anomalies. What if #219 (we can look him up and find it&#8217;s Mark Antony) wants to do a third activity? School rules allow it, but there&#8217;s no space in this structure for another activity. We can&#8217;t add another record for Mark, as that would violate the unique key field ID, and it would also make it difficult to see all his information at once.</li>
<li>Redundant data entry. If the tennis fees go up to $39, we have to go through <em>every</em> record containing tennis and modify the cost in each and every one.</li>
<li>Querying difficulties. It&#8217;s difficult to find all people doing swimming: we have to search through Activity 1 <em>and</em> Activity 2 to make sure we catch them all.</li>
<li>Redundant information. If 50 students take swimming, we have to type in both the activity and its cost each time.</li>
<li>Inconsistent data. Notice that there are conflicting prices for swimming? Should it be $15 or $17? This happens when one record is updated and another isn&#8217;t.</li>
</ol>
<h2>Eliminate recurring fields</h2>
<p>Our simple Students table is fine, so we&#8217;ll keep it. But there&#8217;s so much wrong with the Activities table let&#8217;s try to fix it in stages.</p>
<p><strong>Step 7: Modify the design.</strong> We can fix the first four problems by creating a separate record for each activity a student takes, instead of having one record for all the activities a student takes.</p>
<p>First we eliminate the Activity 2 and Cost 2 fields. Then we need to adjust the table structure so we can enter multiple records for each student. To do that, we redefine the key so that it consists of two fields, ID and Activity. As each student can only take an activity once, this combination gives us a unique key for each record.</p>
<p>Our Activities table has now been simplified to: ID, Activity, Cost. Note how the new structure lets students take any number of activities – they&#8217;re no longer limited to two.</p>
<p><strong>Step 8: Test sample data.</strong></p>
<p><a href="http://www.geekgirls.com/wp-content/uploads/activities_03.gif"><img class="alignnone size-full wp-image-1352" title="Eliminating recurring fields" src="http://www.geekgirls.com/wp-content/uploads/activities_03.gif" alt="Eliminating recurring fields" width="392" height="207" /></a></p>
<p><strong>Step 9: Analyse the data.</strong> We know we still have the problems with redundant data (activity fees repeated) and inconsistent data (what&#8217;s the correct fee for swimming?). We need to fix these things, which are both problems when it comes to data entry &#8211; editing or modifying records.</p>
<h2>Eliminate data entry anomalies</h2>
<p>As well, we should check that other data entry processes, such as adding or deleting records, will function correctly too.</p>
<p>If you look closely, you&#8217;ll find that there are potential problems when we add or delete records:</p>
<ul>
<li>Insertion anomalies. What if our school introduces a new activity, such as sailing, at $50. Where can we store this information? With our current design we can&#8217;t until a student signs up for the activity.</li>
<li>Deletion anomalies. If Mark Antony (#219) transfers to another school, all the information about golf disappears from our system, as he is the only student taking this activity.</li>
</ul>
<p><strong>Step 10: Modify the design. </strong> The cause of all our remaining problems is that we have a non-key field (cost) which is dependent on only part of the key (activity). Check it out for yourself: The cost of each activity is <em> not</em> dependent on the student&#8217;s ID, which is part of our composite key (ID + Activity). The cost of tennis, for example, is $36 for each and every student who takes the sport – so the student&#8217;s ID has no bearing on the value contained in this field. The cost of an activity is purely dependent on the activity itself &#8211; it&#8217;s dependent on only part of the combined ID/activity key. This is a design no-no, and it&#8217;s causing us problems. By checking our table structures and ensuring that <em> every non-key field is dependent on the whole key,</em> we will eliminate the rest of our problems.</p>
<p>Our final design will thus contain three tables: the Students table (Student, ID), a Participants table (ID, Activity), and a modified Activities table (Activity, Cost).</p>
<p>If you check these tables, you&#8217;ll see that each non-key value depends on the whole key: the student name is entirely dependent on the ID; the activity cost is entirely dependent on the activity. Our new Participants table essentially forms a union of information drawn from the other two tables, and each of its fields is part of the key. The tables are linked by key fields: the Students table:ID corresponds to the Participants table:ID; the Activities table:Activity corresponds to the Participants table:Activity.</p>
<p><strong>Step 11: Test sample data.</strong></p>
<p><a href="http://www.geekgirls.com/wp-content/uploads/activities_04.gif"><img class="alignnone size-full wp-image-1353" title="A workable design" src="http://www.geekgirls.com/wp-content/uploads/activities_04.gif" alt="A workable design" width="381" height="355" /></a></p>
<p><strong>Step 12: Analyse the results.</strong> This looks good:</p>
<ul>
<li>No redundant information. You need only list each activity fee once.</li>
<li>No inconsistent data. There&#8217;s only one place where you can enter the price of each activity, so there&#8217;s no chance of creating inconsistent data. Also, if there&#8217;s a fee rise, all you need to do is update the cost in one place.</li>
<li>No insertion anomalies. You can add a new activity to the Activities table without a student signing up for it.</li>
<li>No deletion anomalies. If Mark Antony (#219) leaves, you still retain the details about the golfing activity.</li>
</ul>
<p>Keep in mind that to simplify the process and focus on the relational aspects of designing our database structure, we&#8217;ve placed the student&#8217;s name in a single field. This is not what you&#8217;d normally do: you&#8217;d divide it into firstname, lastname (and initials) fields. Similarly, we&#8217;ve excluded other fields that you would normally store in a student table, such as date of birth, address, parents&#8217; names and so on.</p>
<h2>A summary of the design process</h2>
<p>Although your ultimate design will depend on the complexity of your data, each time you design a database, make sure you do the following:</p>
<ul>
<li>Break composite fields down into constituent parts. Example: Name becomes lastname and firstname.</li>
<li>Create a key field which uniquely identifies each record. You may need to create an ID field (with a lookup table that shows you the values for each ID) or use a composite key.</li>
<li>Eliminate repeating groups of fields. Example: If your table contains fields Location 1, Location 2, Location 3 containing similar data, it&#8217;s a sure warning sign.</li>
<li>Eliminate record modification problems (such as redundant or inconsistent data) and record deletion and addition problems by ensuring each non-key field depends on the <em>entire</em> key. To do this, create a separate table for any information that is used in multiple records, and then use a key to link these tables to one another.</li>
</ul>
<p>Related posts:<ol>
<li><a href='http://www.geekgirls.com/2011/09/databases-from-scratch-ii-simple-database-design/' rel='bookmark' title='Databases from scratch II: Simple Database Design'>Databases from scratch II: Simple Database Design</a></li>
<li><a href='http://www.geekgirls.com/2011/09/databases-from-scratch-i-introduction/' rel='bookmark' title='Databases from scratch I: Introduction'>Databases from scratch I: Introduction</a></li>
<li><a href='http://www.geekgirls.com/2010/03/databasics3-data-entry-design/' rel='bookmark' title='Databasics III: Data entry design'>Databasics III: Data entry design</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.geekgirls.com/2011/09/databases-from-scratch-iii-relational-design-process/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Databases from scratch II: Simple Database Design</title>
		<link>http://www.geekgirls.com/2011/09/databases-from-scratch-ii-simple-database-design/</link>
		<comments>http://www.geekgirls.com/2011/09/databases-from-scratch-ii-simple-database-design/#comments</comments>
		<pubDate>Tue, 27 Sep 2011 22:07:01 +0000</pubDate>
		<dc:creator>rosevines</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Office Apps]]></category>
		<category><![CDATA[database design]]></category>
		<category><![CDATA[dbms]]></category>
		<category><![CDATA[microsoft access]]></category>

		<guid isPermaLink="false">http://www.geekgirls.com/?p=1328</guid>
		<description><![CDATA[The second in a series of articles on choosing, designing and using a database program. This one covers simple table design.]]></description>
			<content:encoded><![CDATA[<p><span class="dropcap">H</span><!--/.dropcap-->ave you ever noticed advertisements in the job classifieds for &#8216;database architects&#8217; or &#8216;database administrators&#8217;? It makes database design sound pretty intimidating, doesn&#8217;t it? If they&#8217;re so difficult to use that they require architects and administrators, what hope do we mere mortals have?</p>
<p>In fact, databases range from being ultra-simple to use to ultra-complex. In the world of personal computers, there are two main types of database programs. At the simple end of the scale are flat-file databases, also called single-file or list managers. These programs are as easy to learn as a word processor or spreadsheets. The initial concepts may take a little more time to absorb than word processing, but they&#8217;re well within anyone&#8217;s grasp. If you&#8217;re using a database at home, in a class at school or in a small club or organisation, chances are the simple flat-file database will fill your needs.</p>
<h2>Relational databases</h2>
<p>Things can get more complex when you use the other type of personal computer database program, called a relational database. With a relational database program you can create a range of databases, from flat-file structures to demanding multi-file systems. If you&#8217;re using a database in your small business, a large organisation, or an ambitious school project, you&#8217;re likely to need at least some of the features of a more complex relational database.</p>
<p>Whichever type of database program you use, the most crucial step in using it is to design your database structure carefully. <strong>The way you structure your data will affect every other action.</strong> It will determine how easy it is to enter information into the database; how well the database will trap inconsistencies and exclude duplicate records; and how flexibly you will be able to get information out of the database.</p>
<h2>A simple example</h2>
<p>Let&#8217;s take an ultra simple example: the phonebook. Say you&#8217;ve been given the job of placing your school or organisation&#8217;s phone directory on computer.</p>
<p>It should be easy: all you need is the name, the address and the phone number of each person. Your initial table design thus consists of three fields: name, address and phone number. Right?</p>
<p>Let&#8217;s check.</p>
<h2>Testing your design</h2>
<p>The way to see if your database design works is to test it with some sample data, so feed the following records into your hypothetical table:</p>
<p>J. T. Apples, 100 Megalong Dr, Haberfield, 4992122<br />
B. York, 2/53 Alice St, Leichhardt, 5050011<br />
M. R. Sullivan, 9 Jay St, Leichhardt, 4893892<br />
B. J. Anderson, 71 Wally Rd, Glebe, 2298310</p>
<p>Now tell the database program to sort the information:</p>
<p>B. J. Anderson, 71 Wally Rd, Glebe, 2298310<br />
B. York, 2/53 Alice St, Leichhardt, 5050011<br />
J. T. Apples, 100 Megalong Dr, Haberfield, 4992122<br />
M. R. Sullivan, 9 Jay St, Leichhardt, 4893892</p>
<h2>Revising your design</h2>
<p>Immediately, you can see this is not what you want. You want the table sorted alphabetically by last name, not initials.</p>
<p>How can you fix this? Well, you could do some complex manipulation using a database feature called &#8216;string functions&#8217; – <em>if</em> your program supports such a feature. Or, you could come up with a better table design in the first place: last name, initials, address and phone number. Feed your test data into this revised structure then tell the database program to sort your table using the last name followed by the initials. This time, you&#8217;ll get the correct alphabetical listing:</p>
<p>Anderson, B. J., 71 Wally Rd, Glebe, 2298310<br />
Apples, J. T., 100 Megalong Dr, Haberfield, 4992122<br />
Sullivan, M. R., 9 Jay St, Leichhardt, 4893892<br />
York, B., 2/53 Alice St, Leichhardt, 5050011</p>
<h2>Keep on refining</h2>
<p>Don&#8217;t stop there. The table can be even more effective if you break the structure down further. For instance, if you&#8217;d like to have an easy way to list only those people who live in Leichhardt, this design won&#8217;t help you. But with a little more work, you can break your database structure down further into last name, initials, street address, suburb, and phone number.</p>
<p>With this structure, you&#8217;ll be able to sort your database alphabetically by last name or by suburb, and you&#8217;ll be able to pluck out all those people who live in a particular suburb.</p>
<div class="woo-sc-box normal   "><strong>A visual example</strong></p>
<p>Here&#8217;s another example of this process in action, starting with a badly designed table structure:</p>
<div id="attachment_1333" class="wp-caption alignnone" style="width: 532px"><a href="http://www.geekgirls.com/wp-content/uploads/flawed_table.gif"><img class="size-full wp-image-1333 " title="A flawed table design" src="http://www.geekgirls.com/wp-content/uploads/flawed_table.gif" alt="A flawed table design" width="522" height="158" /></a><p class="wp-caption-text">Figure 1: A simple – and flawed – students table</p></div>
<p>This fragment of a students table suffers from various defects. The combined name field makes it hard for us to locate students by using their last names, and also difficult to sort the table alphabetically by last name. Even worse, how do we uniquely identify each student? Currently, this table uses a combination of the Name and Date of Birth fields to identify each student. What if we happen to have two Jim Smiths, both born on 5th September 1982? It’s unlikely, yes, but not impossible.</p>
<p>The composite address field is also a problem: for instance, how do we pre-sort mail by postal code so we can do bulk mailouts at discount rates?</p>
<p>By breaking the fields down we end up with double the number of fields but a much simpler and more effective structure. The new Student ID field lets us uniquely identify any student, even when they share names and birthdates. We’ve split the Names field into first and last names so we can get an alphabetical listing. We’ve done the same to the address field, allowing us to sort by postal code or suburb.</p>
<div id="attachment_1334" class="wp-caption alignnone" style="width: 591px"><a href="http://www.geekgirls.com/wp-content/uploads/improved_table.gif"><img class="size-full wp-image-1334  " title="Improved table design" src="http://www.geekgirls.com/wp-content/uploads/improved_table.gif" alt="Improved table design" width="581" height="130" /></a><p class="wp-caption-text">Figure 2: An improved students table</p></div>
</div>
<h2>More is less</h2>
<p>Notice how creating an efficient table structure consists of <em>breaking down</em> your fields into simpler and simpler components? You end up with a table with many more fields than you might originally have thought necessary, but each of those fields houses much more basic information.</p>
<p>There&#8217;s a technical term for this process: normalisation. If you wanted to become a database architect you&#8217;d have to become conversant with <em>normalisation</em> and <em>functional dependencies</em> and <em>normal forms</em>. If you&#8217;re happy to remain a lesser mortal, you can safely ignore these terms, provided you keep in mind that your task is to create a database structure that provides an efficient store for your information and that makes it flexible and easy to extract useful information.</p>
<p>In some ways, creating a database that&#8217;s effective and simple to use is almost an anti-intuitive process. For example, our initial structure for the phone directory:</p>
<p>name<br />
address<br />
phone number</p>
<p>seems like it&#8217;s a simpler design than our end result:</p>
<p>first name<br />
last name<br />
street address<br />
suburb<br />
phone number</p>
<h2>Creating useful fields</h2>
<p>What you need to remember is that while the structure might look more complex, the contents of each field have been reduced to the simplest useful components. I say &#8220;useful&#8221; because we could, of course, break each field down further. For instance, we could break the street address field into two fields, street number and street name. But what would be the point? There&#8217;s no need to extract or sort information in the database simply by street number or name, and so it&#8217;s not a <em>useful</em> basis for breaking up the field. On the other hand, if we wanted to deal with multi-line addresses which are common for businesses, such as:</p>
<p>Suite 5<br />
122 Jones Street</p>
<p>then it makes sense to break the address field down into two simpler fields, address line 1 and address line 2. You&#8217;re not likely to want to sort information based on only one of these fields, nor are you likely to use either of these fields in isolation. What <em>is</em> likely is that you&#8217;ll want to have an easy way to print address line 1 and address line 2 as separate lines when addressing envelopes. So this field division becomes useful when getting information out of your database.</p>
<h2>Permissible design infractions</h2>
<p>I should add that creating these address sub-fields is not, technically, a good solution. Notice how with this table design, many records will have nothing in the address line 2 field, as most people&#8217;s address consists of one line, rather than two. So you&#8217;ll be wasting a lot of space in your database. Additionally, what about addresses that require <em>more</em> than two lines, such as:</p>
<p>Suite 5<br />
Level III, Building A20<br />
122 Jones Street</p>
<p>Our new table structure can&#8217;t cope with this. Should we add another address line to ensure we cater to the infrequent address that needs three lines? Should we add a fourth line just in case…?</p>
<p>You can see the problems you can create by not getting the design right. A technically rigorous solution is to remove the address lines from our phonebook table altogether, and stick them in an address table, that we then link to the phonebook table by a common field.</p>
<p>However, there&#8217;s no need to fuss too much about such details. Many databases get by with minor infractions of database design rules, and you shouldn&#8217;t feel hampered by such rules provided your table structures:</p>
<ul>
<li>provide flexible and simple output (whether you&#8217;re asking an online query of the database or printing reports)</li>
<li>eliminate redundant or duplicated information</li>
<li>exclude inconsistencies</li>
</ul>
<h2>Computer-less design</h2>
<p>One thing I hope you&#8217;ve noticed is that we&#8217;ve done all our design <em>without the aid of a computer</em>. This is as it should be: it lets you focus on the significance of the task without the distractions of trying to learn a database program at the same time.</p>
<p>You can design <em>and</em> test your database structure without going near a computer. The only thing you really need to know is the type of database program you&#8217;ll use: if it&#8217;s a flat-file database, such as Microsoft Works, you&#8217;ll be limited to single-table database design. If it&#8217;s a relational program, such as FileMaker Pro, Microsoft Access or Alpha Five, you can design single- or multi-table databases.</p>
<p>In the next article in this series, we&#8217;ll move on to relational design. You&#8217;ve seen how breaking down your fields into simpler components in a single table can help make it easier to get useful information out of your database. When we look at relational design, you&#8217;ll discover how extending this process lets you address the other two goals of database design: eliminating redundant information and excluding inconsistencies.</p>
<p>Related posts:<ol>
<li><a href='http://www.geekgirls.com/2011/09/databases-from-scratch-iii-relational-design-process/' rel='bookmark' title='Databases from scratch III: The Design Process'>Databases from scratch III: The Design Process</a></li>
<li><a href='http://www.geekgirls.com/2011/09/databases-from-scratch-i-introduction/' rel='bookmark' title='Databases from scratch I: Introduction'>Databases from scratch I: Introduction</a></li>
<li><a href='http://www.geekgirls.com/2011/09/which-database-series-should-i-read/' rel='bookmark' title='Which database series should I read?'>Which database series should I read?</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.geekgirls.com/2011/09/databases-from-scratch-ii-simple-database-design/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Databases from scratch I: Introduction</title>
		<link>http://www.geekgirls.com/2011/09/databases-from-scratch-i-introduction/</link>
		<comments>http://www.geekgirls.com/2011/09/databases-from-scratch-i-introduction/#comments</comments>
		<pubDate>Tue, 27 Sep 2011 16:12:02 +0000</pubDate>
		<dc:creator>rosevines</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Office Apps]]></category>
		<category><![CDATA[database design]]></category>
		<category><![CDATA[dbms]]></category>
		<category><![CDATA[filemaker]]></category>
		<category><![CDATA[microsoft access]]></category>
		<category><![CDATA[relational database]]></category>

		<guid isPermaLink="false">http://www.geekgirls.com/?p=1308</guid>
		<description><![CDATA[The first in a series of articles on choosing, designing and using a database program.]]></description>
			<content:encoded><![CDATA[<p><em></em><span class="dropcap">W</span><!--/.dropcap-->hen I was eighteen, I had a holiday job in an obscure back office of the New South Wales Stamp Duties Office. It doesn&#8217;t take an overactive imagination to realise that a temporary position in this bureaucratic outpost was not the most exhilarating of experiences.</p>
<p>The work reached its low point when I was given the job of renumbering – <em>by hand</em> – 30,000 filecards. The cards were numbered from 1 to 30,000 and the powers that be wanted them renumbered 0 to 29,999 so that each batch of 100 cards would start with the same digits.</p>
<p>If only those filecards had been on a computer database! With a computer, this mind-numbing job, which took me several weeks to complete, could have been done in a matter of seconds. In fact, it would have been an utterly trivial task.</p>
<h2>The emergence of databases</h2>
<p>Unfortunately, at the time I was suffering in the Stamp Duties Office, in the mid-70s, computer databases as we know them today were in their infancy. Around 1970 a researcher called Ted Codd had developed the &#8220;relational data model&#8221;, which was to become the foundation stone of modern database technology. In the mid-70s, however, computer databases – particularly in the hands of end users – were not a common thing.</p>
<p>It wasn&#8217;t until the beginning of the &#8217;80s, with the development of dBASE II (there was no dBASE I), that microcomputer-based databases started coming into their own. Although riddled with bugs, dBASE put enormous power into the hands of microcomputer developers and it remained the pre-eminent database program until the advent of Windows 3.x. With Windows 3 came a new breed of PC database, designed to be much easier to use than their DOS-based predecessors.</p>
<p>Today, there are many database products to choose from, ranging from programs designed for developers to simple databases for average computer users to niche databases designed for specific purposes, such as library catalogues and classroom scheduling.</p>
<h2>What is a database?</h2>
<p>Let&#8217;s take a step back and define exactly what a database is. If spreadsheets are the &#8216;number crunchers&#8217; of the digital world, databases are the real &#8216;information crunchers&#8217;. Databases excel at managing and manipulating structured information.</p>
<p>What does the term &#8216;structured information&#8217; mean? Consider one of the most familiar databases – the phone book. The phone book contains several items of information – name, address and phone number – about each phone subscriber in a particular area. Each subscriber&#8217;s information takes the same form.</p>
<p>In database parlance, the phone book is a <em>table</em> which contains a <em>record</em> for each subscriber. Each subscriber record contains three <em>fields</em><em>:</em> name, address, and phone number. Each field contains a specific piece of information about the subscriber. The records are sorted alphabetically by the name field, which is called the <em>key field.</em></p>
<p>Other examples of databases are club membership lists, customer lists, library catalogues, business card files, class schedules and parts inventories. The list is, in fact, infinite. Using a <em>database program</em> you can design a database to do anything from tracking the breeding program on a horse stud to collecting information from the Mars Rover. And increasingly, databases are being used to build websites.</p>
<h2>Single and multi-file databases</h2>
<div id="attachment_1312" class="wp-caption alignright" style="width: 532px"><a href="http://www.geekgirls.com/wp-content/uploads/flat01.jpg"><img class="size-full wp-image-1312" title="Single-file database" src="http://www.geekgirls.com/wp-content/uploads/flat01.jpg" alt="Single-file database" width="522" height="155" /></a><p class="wp-caption-text">The simplest form of database consists of a single table of information about a particular topic. If you visualise the phone book as a table consisting of rows and columns, each row represents one phone subscriber’s record. Each column represents a field, which contains the same type of information for each subscriber.</p></div>
<p>A database can contain a single table of information, such as the phone book, or many tables of related information. An order entry system for a business, for example, will consist of many tables:</p>
<ul>
<li>an orders table to track each order</li>
<li>an orders detail table for tracking each item in an order</li>
<li>a customer table so you can see who made the order and who to bill</li>
<li>an inventory table showing the goods you have on hand</li>
<li>a suppliers table, so you can see who you need to re-order your stock from</li>
<li>a payments table to track payments for orders</li>
</ul>
<p>Each of these tables will be linked to one or more of the other tables, so that you can tie information together to produce reports or answer questions about the information you have in your database.</p>
<p>Multi-file databases like this are called <em>relational databases</em>. It&#8217;s relational databases, as we&#8217;ll see later in this series, that provide exceptional power and flexibility in storing and retrieving information.</p>
<h2>A multi-file example</h2>
<p><a href="http://www.geekgirls.com/wp-content/uploads/simple_relational1.jpg"><img class="alignright size-full wp-image-1317" title="A simple relational database" src="http://www.geekgirls.com/wp-content/uploads/simple_relational1.jpg" alt="A simple relational database" width="456" height="294" /></a>Relational databases are made up of two or more tables of information which are connected in some way. The very simple example shown here depicts a database used to track reviews of Internet sites published by a computer magazine.</p>
<p>There are two tables in the database. The first is the <em>Reviews table</em> which includes information about each site, the review itself, and who wrote the review. The second is the <em>Categories table</em> containing a list of site categories. This table contains just two fields, the category ID and the category name, and it is linked to the Reviews table via the CategoryID field.</p>
<p>You might wonder, why don&#8217;t we put the category information directly in the Reviews table?</p>
<p>One reason is to maintain consistency of the information stored in the database. If you enter the category information directly into the Reviews table, it&#8217;s easy to end up with one site&#8217;s category listed as, say, &#8220;news commentary&#8221; while a similar site is listed as &#8220;news opinion&#8221; and yet another as &#8220;news columnist&#8221;, when really they all belong to the same category. This is not much of a problem in a small database, but if you have thousands of site reviews in your table, it&#8217;s very easy for such problems to multiply. If you try to do a search for &#8220;news commentary&#8221; on this table, you won&#8217;t find the sites categorised as &#8220;news opinion&#8221; or &#8220;news columnist&#8221;, even though you&#8217;d hope to include them in the result.</p>
<p>On the other hand, if you store your category information in its own table, discrepancies such as this become immediately apparent and it&#8217;s a simple matter to eliminate misnamed categories. By then linking the two tables, you can pull information from the Categories table into the Reviews table (it&#8217;s known as performing a <em>lookup</em>).</p>
<h2>Database programs</h2>
<p>To create and maintain a computer database, you need a database program, often called a database management system, or DBMS. Just as databases range from simple, single-table lists to complex multi-table systems, database programs, too, range in complexity.</p>
<p>Some, such as the database component of Microsoft Works, are designed purely to manage single-file databases. With such a product you cannot build a multi-table database. You can certainly create numerous tables for storing different types of information, but there&#8217;s no way to link information from one table to another. Such programs are sometimes called flat-file databases, or list managers.</p>
<p>Other database programs, called relational database programs or RDBMSs, are designed to handle multi-file databases. Some of the most popular relational databases are Microsoft Access, FileMaker Pro, Bento (on the Mac) and Alpha Five.</p>
<h2>Database program tools</h2>
<p>A database program gives you the tools to:</p>
<ul>
<li>design the structure of your database</li>
<li>create data entry forms so you can get information into the database</li>
<li>validate the data entered and check for inconsistencies</li>
<li>sort and manipulate the data in the database</li>
<li>query the database (that is, ask questions about the data)</li>
<li>produce flexible reports, both on screen and on paper, that make it easy to comprehend the information stored in the database.</li>
</ul>
<p>Most of the more advanced database programs have built-in programming or macro languages, which let you automate many of their functions.</p>
<h2>Using a database</h2>
<p>If the mention of programming languages makes you feel you&#8217;re getting out of your depth, don&#8217;t worry! Most of the database programs you&#8217;re likely to encounter can be used at a variety of levels.</p>
<p>If you&#8217;re a beginner, you&#8217;ll find built-in templates, sample databases, &#8216;wizards&#8217; and &#8216;experts&#8217; that will do much of the hard work for you. If you find the built-in databases don&#8217;t quite work for you, it&#8217;s easy to modify an existing database so it fits your needs, and it&#8217;s not at all difficult to learn to create your own simple database structure from scratch.</p>
<p>For more advanced users, the more powerful database programs enable you to create complete, custom-built, application-specific systems which can be used by others in your organisation or business.</p>
<h2>When not to use a database</h2>
<p>Even though you can use a database program to do anything from managing the inventory of a parts supply warehouse to managing your personal finances, sometimes the smart option is to not use a database at all. That&#8217;s because there&#8217;s no point in reinventing the wheel: If you want a personal financial manager, you&#8217;re far better off spending money on one of the commercial programs, such as Quicken or MoneyDance, than slaving for weeks creating your own version of the same thing.</p>
<p>The same goes for vertical market applications. Before you spend months designing a church contribution application or that parts inventory system, do a Google or check your local software supplier to see if something similar has already been created.</p>
<h2>Planning ahead</h2>
<p>There&#8217;s one crucial thing you need to do whenever you create a database: plan ahead. Whether it&#8217;s a single table or a collection of tables, you need to look at the information you want to store and the ways you want to retrieve that information <em>before you start working on the computer.</em> That&#8217;s because a poorly structured database will hamstring you further down the track when you try to get your information back out in a usable form.</p>
<p>We&#8217;ll look at database design in detail in the next articles in this series.</p>
<p>Related posts:<ol>
<li><a href='http://www.geekgirls.com/2011/09/databases-from-scratch-ii-simple-database-design/' rel='bookmark' title='Databases from scratch II: Simple Database Design'>Databases from scratch II: Simple Database Design</a></li>
<li><a href='http://www.geekgirls.com/2011/09/databases-from-scratch-iii-relational-design-process/' rel='bookmark' title='Databases from scratch III: The Design Process'>Databases from scratch III: The Design Process</a></li>
<li><a href='http://www.geekgirls.com/2011/09/which-database-series-should-i-read/' rel='bookmark' title='Which database series should I read?'>Which database series should I read?</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.geekgirls.com/2011/09/databases-from-scratch-i-introduction/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

