<?xml version="1.0"?>
<rss version="2.0">
  <channel>
    <title><![CDATA[LinLog]]></title>
    <link>https://linlog.skepticats.com/</link>
    <description><![CDATA[Linux, Programming, and Computing in General]]></description>
    <lastBuildDate>2022-09-16T16:00:21+00:00</lastBuildDate>
    <managingEditor>pageer@skepticats.com (Peter Geer)</managingEditor>
    <language>en-US</language>
    <generator>https://lnblog.skepticats.com/?v=2.2.0</generator>
    <item>
      <title><![CDATA[MySQL comment weirdness ]]></title>
      <link>https://linlog.skepticats.com/entries/2008/10/MySQL_comment_weirdness.php</link>
      <description><![CDATA[<p>Here's one I discovered for the first time yesterday - <a href="http://dev.mysql.com/doc/refman/5.0/en/comments.html">MySQL doesn't actually use the ANSI SQL comment sequence</a>.  Who knew?</p><p>For those who are a little rusty on such things, ANSI SQL-92 specifies the comment character as a doule dash (--).  Anything from a double dash to the end of a line is a comment.</p><p>Well, in MySQL, that doesn't actually work.  You <em>have</em> to have a <em>space</em> (or control character) after the double dash for MySQL to treat is as a comment.  This is good style anyway, but MySQL makes it a hard requirement.  Apparently the <a href="http://dev.mysql.com/doc/refman/5.0/en/ansi-diff-comments.html">reason for this</a> is that it can cause conflicts with software that auto-generates really crappy queries.  </p><p>Is it just me, or does that seem like a really gratuitous change?  I mean, I can see their reasons - it would be nice if an auto-generated query like <code>UPDATE account SET credit=credit--1</code> actually worked instead of reducing to a no-op.  But, on the other hand, is it really a good idea to change the database server because some vendor is too lazy to make their query-generator produce the more correct and logically equivalent <code>UPDATE account SET credit=credit+1</code> instead?  I don't know.  I'm sure they had their reasons, but it just feels like a half-baked hack to me.</p>]]></description>
      <author><![CDATA[pageer@skepticats.com (Peter Geer)]]></author>
      <pubDate>Wed, 15 Oct 2008 03:33:00 +0000</pubDate>
      <category><![CDATA[Database]]></category>
      <category><![CDATA[MySQL]]></category>
      <category><![CDATA[SQL]]></category>
      <guid isPermalink="true">https://linlog.skepticats.com/entries/2008/10/MySQL_comment_weirdness.php</guid>
      <comments>https://linlog.skepticats.com/entries/2008/10/14_2333/comments/</comments>
    </item>
    <item>
      <title><![CDATA[Keys and NULLs  ]]></title>
      <link>https://linlog.skepticats.com/entries/2008/10/Keys_and_NULLs.php</link>
      <description><![CDATA[<p>Well, the cat is currently laying on the book I was trying to read, so I guess I might as well blog.</p><p>Note to self: the rule in SQL is that you can have NULLs in <em>foreign</em> keys, but not in <em>primary</em> keys.  Edwin asked me a question related to this the other day and I had to stop and think about it for a couple of minutes, so I figured I'd write it out to reinforce the concept in my own mind.</p><p>When you think about it, these rules make perfect sense.  Since NULLs in SQL denote an unknown or inapplicable value, having one in a primary key would be nonsense, because a primary key must uniquely identify a row.  Having a NULL in the key would mean part of the unique value was unknown.  (Note that you can't say that a tuple with a NULL in it is unique because one NULL is not equal to another due to the 3-valued logic used by SQL.)</p><p>As for foreign keys, SQL  gives the &quot;benefit of the doubt.&quot;  If you think of a NULL as an unknown value which <em>may</em> later become known, this makes sense.  Sometimes you might have to add the values of foriegn keys in multiple operations, which would not be allowed if NULLs were blocked by the constraint.</p><p>From a logical point of view, this is kind of an interesting case as well.  You can view a foreign key constraint check as a conjunction of equivalence checks.  For example if T1(c1, c2) is foreign keyed to T2(c1, c2), then the constraint check can be viewed as the expression <code>T1.c1 = T2.c1 AND T1.c2 = T2.c2</code>.  In other words, if all the key fields match on both records, the constraint is satisfied.  If not, it fails.  However, with NULLs, the value of one of the conjuncts would be NULL, which would render the entire expression NULL.  </p><p>But what would that mean?  </p><p>The <abbr title="DataBase Management System">DMBS</abbr> can't say that it <em>doesn't know</em> if a relational constraint holds or not.  So, given the interpretation of NULL, it makes sense to use the &quot;benefit of the doubt&quot; principle and defer final judgement on the constraint until all the NULLs are filled in.</p>]]></description>
      <author><![CDATA[pageer@skepticats.com (Peter Geer)]]></author>
      <pubDate>Sun, 12 Oct 2008 03:39:23 +0000</pubDate>
      <category><![CDATA[Database]]></category>
      <category><![CDATA[SQL]]></category>
      <category><![CDATA[Computer Science]]></category>
      <guid isPermalink="true">https://linlog.skepticats.com/entries/2008/10/Keys_and_NULLs.php</guid>
      <comments>https://linlog.skepticats.com/entries/2008/10/11_2339/comments/</comments>
    </item>
  </channel>
</rss>
