<?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>ShinyLight Development &#187; SQLite</title>
	<atom:link href="http://www.shinylight.com/category/databases/sqlite/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.shinylight.com</link>
	<description>Web Development and Other Goodness in the World of a Software Engineer.</description>
	<lastBuildDate>Mon, 07 Jun 2010 03:02:19 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Logical vs Physical ER Diagrams</title>
		<link>http://www.shinylight.com/2010/01/24/logical-vs-physical-er-diagrams/</link>
		<comments>http://www.shinylight.com/2010/01/24/logical-vs-physical-er-diagrams/#comments</comments>
		<pubDate>Sun, 24 Jan 2010 05:54:54 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQLite]]></category>

		<guid isPermaLink="false">http://www.shinylight.com/?p=721</guid>
		<description><![CDATA[Logical diagrams are to convey  requirements only. Physical diagrams represent the actual data structure to  support the requirements and take into account technical scalability and speed. 
Edit: I hate the way I had to format this document for this blog post. If you want this tutorial better formatted, check out the Word document. [...]]]></description>
			<content:encoded><![CDATA[<p>Logical diagrams are to convey  requirements only. Physical diagrams represent the actual data structure to  support the requirements and take into account technical scalability and speed. </p>
<p><strong>Edit:</strong> I hate the way I had to format this document for this blog post. If you want this tutorial better formatted, check out the <a href="/wp-content/uploads/2010/01/Logical-vs-Physical.doc">Word document.</a> </p>
<h2>One-to-Many Relationship</h2>
<p><br /></p>
<p><strong>Logical</strong></p>
<p align="center"><img src="/wp-content/uploads/2010/01/image001.jpg" width="286" height="144" /></p>
<p>On ER/Studio, two tables are created. The Store table    has a primary key StoreID. The Manager table has a primary key, ManagerID and    a foreign key, StoredID (which is mapped to StoreID from the Store table).</p>
<p><strong>Physical</strong></p>
<table width="200" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2"><img src="/wp-content/uploads/2010/01/image002.jpg" width="358" height="138" /></td>
</tr>
<tr>
<td><img src="/wp-content/uploads/2010/01/image003.jpg" width="136" height="19" /></td>
<td><img src="/wp-content/uploads/2010/01/image004.jpg" width="149" height="36" /></td>
</tr>
</table>
<p>
  On SQL Server, two tables are created. The Store table    has a primary key StoreID. The Manager table has a primary key, ManagerID and    a foreign key, StoredID (which is mapped to StoreID from the Store table).</p>
<p align="center">Manager Table:<br />
  <img src="/wp-content/uploads/2010/01/image005.jpg" width="333" height="97" /></p>
<p>If you allow NULLs for StoreID in the Manager table,    then you’ll be able to have a Manager without a store. If you don’t allow    NULLs (leave it unchecked), then you’ll have to have at least one Store    assigned to a Manager. </p>
<p><strong>Querying</strong></p>
<p>The above states that one store can have many managers. Here’s some sample data what’s in the tables:</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">*</span> <span style="color: #0000FF;">FROM</span> Manager</pre></div></div>

<div align="center">
  <img src="/wp-content/uploads/2010/01/image006.jpg" width="240" height="171" />
  </p>
</div>
<p>
<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">*</span> <span style="color: #0000FF;">FROM</span> Store</pre></div></div>

<div align="center">
  <img src="/wp-content/uploads/2010/01/image007.jpg" width="414" height="77" />
  </p>
</div>
<p>Get all manager information with for all managers that  belong to a store:</p>
<table width="100%" border="0" cellspacing="5" cellpadding="3">
<tr>
<td>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">SELECT</span>  Manager.<span style="color: #202020;">ManagerID</span>,  Manager.<span style="color: #202020;">FirstName</span>,  Manager.<span style="color: #202020;">LastName</span>,  Manager.<span style="color: #202020;">StoreID</span>,
        Store.<span style="color: #808080;">&#91;</span>Name<span style="color: #808080;">&#93;</span>,  Store.<span style="color: #202020;">Address</span>,  Store.<span style="color: #0000FF;">STATE</span>,  Store.<span style="color: #202020;">City</span>,  Store.<span style="color: #202020;">Zip</span>
<span style="color: #0000FF;">FROM</span>    Manager
        <span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span> Store <span style="color: #0000FF;">ON</span> Manager.<span style="color: #202020;">StoreID</span> <span style="color: #808080;">=</span> Store.<span style="color: #202020;">StoreID</span></pre></div></div>

</td>
</tr>
<tr>
<td>
<div align="center"><img src="/wp-content/uploads/2010/01/image008.jpg" width="597" height="156" /></div>
</td>
</tr>
</table>
<p><br /></p>
<p>Get all manager information with for all managers (even  if they don’t have a store):</p>
<table width="101%" border="0" cellspacing="5" cellpadding="3">
<tr>
<td>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">SELECT</span>  Manager.<span style="color: #202020;">ManagerID</span>,  Manager.<span style="color: #202020;">FirstName</span>,  Manager.<span style="color: #202020;">LastName</span>,  Manager.<span style="color: #202020;">StoreID</span>,
        Store.<span style="color: #808080;">&#91;</span>Name<span style="color: #808080;">&#93;</span>,  Store.<span style="color: #202020;">Address</span>,  Store.<span style="color: #0000FF;">STATE</span>,  Store.<span style="color: #202020;">City</span>,  Store.<span style="color: #202020;">Zip</span>
<span style="color: #0000FF;">FROM</span>    Manager
        <span style="color: #0000FF;">LEFT</span> <span style="color: #808080;">OUTER</span> <span style="color: #808080;">JOIN</span> Store <span style="color: #0000FF;">ON</span> Manager.<span style="color: #202020;">StoreID</span> <span style="color: #808080;">=</span> Store.<span style="color: #202020;">StoreID</span></pre></div></div>

</td>
</tr>
<tr>
<td>
<div align="center"><img src="/wp-content/uploads/2010/01/image009.jpg" width="604" height="172" /></div>
</td>
</tr>
</table>
<p><br /></p>
<p>Notice the NULL for Steamboat Willie. He doesn’t have a  store, so all Store related fields show as NULL.</p>
<p><br /></p>
<h2>Many-to-Many Relationship</h2>
<p>
<br />
</p>
<p>In order to implement this  physically, you need a join table. In this case, we use StoreManager.  Logically, you only need only two entities (Store and Manager).</p>
<p><strong>Logical</strong></p>
<p align="center"><img src="/wp-content/uploads/2010/01/image010.gif" width="290" height="148" /></p>
<p><strong>Physical</strong></p>
<table width="200" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2"><img src="/wp-content/uploads/2010/01/image011.jpg" width="156" height="34" /></td>
</tr>
<tr>
<td colspan="2"><img src="/wp-content/uploads/2010/01/image012.jpg" width="341" height="211" /></td>
</tr>
<tr>
<td><img src="/wp-content/uploads/2010/01/image013.jpg" width="146" height="20" /></td>
<td><img src="/wp-content/uploads/2010/01/image014.jpg" width="135" height="15" /></td>
</tr>
</table>
<p><br /></p>
<p>
  On SQL Server, three tables are created. The Store    table has a primary key StoreID. The Manager table has a primary key,    ManagerID. The table StoreManager has two foreign keys:  StoredID (which is    mapped to StoreID from the Store table) and ManagerID (which is mapped to the    ManagerID from the Manager table). </p>
<p align="center">StoreManager Table:<br />
  <img src="/wp-content/uploads/2010/01/image015.jpg" width="311" height="56" /></p>
<p>If you allow NULLs for StoreID and ManagerID in the StoreManager    table, then you’ll be able to have a Manager without a store. If you don’t    allow NULLs (leave it unchecked for both), then you’ll have to have at least    one Store assigned to a Manager. </p>
<p>Here’s some sample data what’s in the tables:</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">*</span> <span style="color: #0000FF;">FROM</span> Manager</pre></div></div>

<p align="center"><img src="/wp-content/uploads/2010/01/image016.jpg" width="157" height="140" /></p>
<p><br /></p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">*</span> <span style="color: #0000FF;">FROM</span> Store</pre></div></div>

<p align="center"><img src="/wp-content/uploads/2010/01/image017.jpg" width="331" height="65" /></p>
<p><br /></p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">*</span> <span style="color: #0000FF;">FROM</span> StoreManager</pre></div></div>

<p align="center"><img src="/wp-content/uploads/2010/01/image018.jpg" width="73" height="204" />
</p>
<p><br /></p>
<p>Get all manager information associated with his store:</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">SELECT</span>  Manager.<span style="color: #202020;">ManagerID</span>,  Manager.<span style="color: #202020;">FirstName</span>,  Manager.<span style="color: #202020;">LastName</span>,
        StoreManager.<span style="color: #202020;">StoreID</span>, StoreManager.<span style="color: #202020;">ManagerID</span>, Store.<span style="color: #202020;">StoreID</span>,
        Store.<span style="color: #808080;">&#91;</span>Name<span style="color: #808080;">&#93;</span>,Store.<span style="color: #202020;">Address</span>, Store.<span style="color: #0000FF;">STATE</span>, Store.<span style="color: #202020;">City</span>, Store.<span style="color: #202020;">Zip</span>
<span style="color: #0000FF;">FROM</span>    Store
        <span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span> StoreManager <span style="color: #0000FF;">ON</span> Store.<span style="color: #202020;">StoreID</span> <span style="color: #808080;">=</span> StoreManager.<span style="color: #202020;">StoreID</span>
        <span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span> Manager <span style="color: #0000FF;">ON</span> StoreManager.<span style="color: #202020;">ManagerID</span> <span style="color: #808080;">=</span> Manager.<span style="color: #202020;">ManagerID</span></pre></div></div>

<div align="center"><img src="/wp-content/uploads/2010/01/image019.jpg" width="600" height="316" /></p>
</div>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em></em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http://www.shinylight.com/2010/01/24/logical-vs-physical-er-diagrams/&amp;submitHeadline=Logical+vs+Physical+ER+Diagrams&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://www.shinylight.com/2010/01/24/logical-vs-physical-er-diagrams/&amp;title=Logical+vs+Physical+ER+Diagrams" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://www.shinylight.com/2010/01/24/logical-vs-physical-er-diagrams/&amp;title=Logical+vs+Physical+ER+Diagrams" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://www.shinylight.com/2010/01/24/logical-vs-physical-er-diagrams/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://www.shinylight.com/2010/01/24/logical-vs-physical-er-diagrams/&amp;title=Logical+vs+Physical+ER+Diagrams" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http://www.shinylight.com/2010/01/24/logical-vs-physical-er-diagrams/&amp;bm_description=Logical+vs+Physical+ER+Diagrams" rel="nofollow" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http://www.shinylight.com/2010/01/24/logical-vs-physical-er-diagrams/&amp;T=Logical+vs+Physical+ER+Diagrams" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://www.shinylight.com/2010/01/24/logical-vs-physical-er-diagrams/&amp;title=Logical+vs+Physical+ER+Diagrams" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://www.shinylight.com/2010/01/24/logical-vs-physical-er-diagrams/&amp;title=Logical+vs+Physical+ER+Diagrams" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://www.shinylight.com/2010/01/24/logical-vs-physical-er-diagrams/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http://www.shinylight.com/2010/01/24/logical-vs-physical-er-diagrams/" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Logical+vs+Physical+ER+Diagrams+@+http://www.shinylight.com/2010/01/24/logical-vs-physical-er-diagrams/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://www.shinylight.com/2010/01/24/logical-vs-physical-er-diagrams/&amp;t=Logical+vs+Physical+ER+Diagrams" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.shinylight.com/2010/01/24/logical-vs-physical-er-diagrams/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
