<?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>Huddled Masses &#187; Databases</title>
	<atom:link href="http://huddledmasses.org/tag/databases/feed/" rel="self" type="application/rss+xml" />
	<link>http://huddledmasses.org</link>
	<description>You can do more than breathe for free...</description>
	<lastBuildDate>Sat, 28 Jan 2012 21:37:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<cloud domain='huddledmasses.org' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title>Rant: Sometimes I hate my job</title>
		<link>http://huddledmasses.org/rant-sometimes-i-hate-my-job/</link>
		<comments>http://huddledmasses.org/rant-sometimes-i-hate-my-job/#comments</comments>
		<pubDate>Wed, 09 Jul 2008 18:08:52 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Rants]]></category>

		<guid isPermaLink="false">http://HuddledMasses.org/?p=564</guid>
		<description><![CDATA[So I&#8217;ve been asked to add a feature to one of the apps that I nominally took over when my former manager left &#8230; they want a management pane where certain authorized super users (to be decided later) can add data to the main lookup tables, and must be able to do clean up by [...]]]></description>
			<content:encoded><![CDATA[	<p>So I&#8217;ve been asked to add a feature to one of the apps that I <em>nominally</em> took over when my former manager left &#8230; they want a management pane where certain authorized super users (to be decided later) can add data to the main lookup tables, and must be able to do clean up by deleting data which has been entered erroneously &#8230; including cleaning up any references to the now missing data.</p>

	<p>I&#8217;m currently trying to figure out what database tables I need to be concerned with, and I just have to vent, because this system is the worst mess I&#8217;ve ever seen.  <img src='http://huddledmasses.org/wordpress/wp-includes/' alt='[disgust]' class='wp-smiley' /> </p>

	<ul>
		<li>There&#8217;s one database supporting five or more applications&#8230;</li>
		<li>There are 87 tables (with names like tblAQ_DcSs, tblAQ_SwNw, tblSFM, and tblSW_PWSOS, tblTestCaseTestLayout )</li>
		<li>There are <strong>three</strong> duplicate user tables: tblPeopleLookup, tblUser, and tblUser3 &#8212; tblUser2 is a view onto an external user database which is what is <strong>supposedly</strong> being used &#8230; and apparently, tblPeopleLookup is some sort of mapping from tblUser2 to tblUser3 &#8230; and tblUser1 is the original user table. I don&#8217;t know why these are all still here &#8212; I can only hope none of these others are still being used.</li>
		<li>There are 144 stored procedures (with names like sp_Fix, sp_Fix2, sp_Fix3, spLeftToTestMulti, spLeftToTestMulti2, spLeftToTestMulti3, sp_Whatever, and the awesome spTestCaseTestLayoutTestsUpdate, spTestCaseTestLayoutTestsSelect, etc.)</li>
	</ul>
	<ul>
		<li>There are <strong>no</strong> Foreign Keys.  Yeah. None.  <img src='http://huddledmasses.org/wordpress/wp-includes/' alt='[crazy]' class='wp-smiley' /> </li>
	</ul>

	<p>Technically, there are lots of foreign keys &#8212; it&#8217;s just that none of them are declared as such, so there&#8217;s no referential integrity (did I mention that there&#8217;s an access database floating around out there with linked tables and a hard-coded login which the end-users pass around to each other so they can insert data into some of the tables <strong>by hand</strong> because the original developers didn&#8217;t get around to writing this management app that I&#8217;ve been asked to write now?)</p>

	<p>You can tell that some of the columns <em>should</em> be Foreign Keys, because obviously a column in a &#8220;tblReq_Tag&#8221; table named &#8220;Feature_ID&#8221; must be an external lookup of some sort &#8230; but there&#8217;s 86 other tables &#8230; and at least two of them have Primary Keys called &#8220;Feature_ID&#8221; ...</p>

	<p>So, I&#8217;m spending a lot of time searching the source code and the 144 stored procedures &#8230; An astonishing number of these stored procedures involve cursors and multiple nested case statements.  I just picked one at random which I thought sounded simple: <strong>spEnterGroupResults</strong> ... it&#8217;s about 150 lines of <span class="caps">SQL</span>, and it uses a single cursor variable &#8220;crsUnit&#8221; which it redefines three separate times onto three different queries which it iterates over. Each of these queries involves joins onto nested subqueries, and I count myself lucky because the tricky part is actually enclosed in a transaction, and at least <em>this one</em> isn&#8217;t doing all of that just to dynamically generate a further <span class="caps">SQL</span> query to execute.</p>

	<p>So yeah, I&#8217;m literally looking through source code to try to understand the database design.  The problem is that there are more than five different applications, each using slightly different technologies.</p>

	<ul>
		<li>One of them which has never been migrated from classic <span class="caps">ASP</span> ... with the business logic written entirely in Javascript, and the data handling performed entirely by sending <strong>huge</strong> <span class="caps">XML</span> files back and forth to a &#8220;do all&#8221; webservice.</li>
		<li>One of them was written in VB.<span class="caps">NET</span> in VS 2003, and has never been upgraded.</li>
	</ul>
	<ul>
		<li>The rest are in C# &#8212; with most in VS 2005, and at least one in VS 2008 and C# 3.0 &#8212; some are Asp.Net, some are rich client &#8230;</li>
	</ul>

	<p>The tables I&#8217;m most concerned with right now (for this app) have some <em>ahem</em> ... impressive design decisions of their own.  Of the 8 tables that I&#8217;m looking at directly (I think these are the only ones I need to <em>modify</em> as part of this app), five of them have multi-column primary keys that involve more than half the columns in the table, including columns which are, in fact, unconstrained foreign keys.  And there are so far 5 foreign key looking columns which I haven&#8217;t been able to find the primary key column for &#8230;  <img src='http://huddledmasses.org/wordpress/wp-includes/' alt='[pullhair]' class='wp-smiley' /> </p>

	<p> <img src='http://huddledmasses.org/wordpress/wp-includes/' alt='[new]' class='wp-smiley' />  <strong>Edit</strong>: Oh yeah, and half of these tables have columns like <code>[Enabled] [char](1) NULL</code> &#8230;  That&#8217;s a <strong>boolean</strong> value folks, stored in the database as a <code>y</code> or a <code>n</code> &#8230; and it&#8217;s nullable even though a null (or any value other than <code>y</code> or <code>n</code>, really) will most likely blow up some code somewhere.  And no, there&#8217;s no script constraint or trigger to ensure that this doesn&#8217;t happen (I checked). For extra fun, the other half of the tables use &#8216;bit&#8217; columns for things like this  &#8212; because they were written after I started working with this team (on a different project) and happened across one of these char columns during our one and only code review ever and wondered aloud why we needed to pretend it was still 1992.  Why they just switched, without changing the others, I&#8217;ll never know&#8230;</p>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/rant-sometimes-i-hate-my-job/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

