<?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>Maggie Nelson &#187; mysql</title>
	<atom:link href="http://maggienelson.com/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://maggienelson.com</link>
	<description>databases and code goodness</description>
	<lastBuildDate>Tue, 06 Apr 2010 17:24:02 +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>The Rules of (Software) Engagement</title>
		<link>http://maggienelson.com/2009/03/the-rules-of-software-engagement/</link>
		<comments>http://maggienelson.com/2009/03/the-rules-of-software-engagement/#comments</comments>
		<pubDate>Mon, 09 Mar 2009 02:45:31 +0000</pubDate>
		<dc:creator>maggie</dc:creator>
				<category><![CDATA[entry]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[standards]]></category>

		<guid isPermaLink="false">http://maggienelson.com/?p=217</guid>
		<description><![CDATA[Being an Oracle fan, I often find myself on the defense trying to explain its awesomeness  While it&#8217;s uber expensive, obviously it has desirable features that sometimes make it worth it. On the other hand, in my experience, Oracle takes a much stricter, &#8220;comp-sci&#8221; (quotes on purpose) approach while MySQL can be wonderful in [...]]]></description>
			<content:encoded><![CDATA[<p>Being an Oracle fan, I often find myself on the defense trying to explain its awesomeness  While it&#8217;s uber expensive, obviously it has desirable features that sometimes make it worth it. On the other hand, in my experience, Oracle takes a much stricter, &#8220;comp-sci&#8221; (quotes on purpose) approach while MySQL can be wonderful in forgiving developers and expecting that developers are more concerned with getting stuff done rather than being nitpicky (which is true most of the time, really).</p>
<p>Allow me to elaborate.  There are a few features that are available to MySQL developers that are a bit harder to find if you&#8217;re using Oracle.  Here are a couple:</p>
<p>This one&#8217;s kind of a cliche and if I had $1 for every time I heard it, I&#8217;d have maybe $20 by now!</p>
<blockquote><p>&#8220;Oracle doesn&#8217;t have SHOW CREATE TABLE!&#8221;</p></blockquote>
<p>So let&#8217;s level the playing field a little bit.  First off, MySQL doesn&#8217;t offer &#8220;show create table&#8221; either.  When you see:</p>
<blockquote>
<pre>
mysql>
</pre>
</blockquote>
<p>you&#8217;re actually running a MySQL client that provides this functionality.  With Oracle, the somewhat default client is <a href="http://download.oracle.com/docs/cd/B19306_01/server.102/b14357/ch3.htm">sqlplus</a> &#8211; it offers access, but it&#8217;s not very fancy.  You can use <a href="http://gqlplus.sourceforge.net/">gqlplus</a> (built by the open source community!) for things like command line history (aka &#8220;arrow up to previous query&#8221;), or go full GUI experience with <a href="http://www.oracle.com/technology/software/products/sql/index.html">SQL Developer</a> (which I personally recommend, it&#8217;s pretty sweet).  The latter offers functionality that will do the same thing you expect &#8220;show create table&#8221; to do when using MySQL client.</p>
<p>More importantly, Oracle offers an entire set of built-in tables that provide data about your database schema.  Next time you have access to Oracle, try this:</p>
<blockquote>
<pre>
DESCRIBE user_tables;
DESCRIBE user_tab_columns;
DESCRIBE user_constraints;
DESCRIBE all_source;
</pre>
</blockquote>
<p>Oracle offers you <a href="http://download.oracle.com/docs/cd/B19306_01/server.102/b14237/index.htm">hundreds of ways</a> to find out information about your schema.  My hunch is that the reason &#8220;show create table&#8221; does not come in a default client is because of the amount of possibilities this means.  Compare the CREATE TABLE statement available <a href="http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_7002.htm">in Oracle</a> and <a href="http://dev.mysql.com/doc/refman/5.1/en/create-table.html">in MySQL</a>.  There is simply so much that &#8220;show create table&#8221; could show you in Oracle, making choices what to omit and deciding what is default perhaps is better left to developers than to a shell script.  (It is also my belief that your DDL &#8211; how your tables are created &#8211; should be stored as code under version control, so there&#8217;s that.)</p>
<p>Another &#8220;Zomg, MySQL is so much better than Oracle!&#8221; claim I witnessed recently is:</p>
<blockquote><p>&#8220;Oracle doesn&#8217;t have INSERT IGNORE!&#8221;</p></blockquote>
<p>The response is, yes, of course it does, it&#8217;s just not called &#8220;insert ignore&#8221;.  &#8220;Insert ignore&#8221; is MySQL&#8217;s feature that veers away from standard SQL as much as anything else. </p>
<p>So what&#8217;s the deal here?  I find that the best way to find equivalent features between MySQL and Oracle is to take a step back and think in more general, basic language concepts.  What &#8220;insert ignore&#8221; really does is:</p>
<ol>
<li>attempt to insert</li>
<li>if failed due to a constraint violation, continue</li>
</ol>
<p>This looks to me to be simple exception handling!  Oracle comes with PL/SQL, an entire language of its own. Surely it has a way to handle exceptions!  Here are a couple of ways to do &#8220;insert ignore&#8221; in oracle:</p>
<blockquote>
<pre>
begin
    insert into some_table(field) values ('zomg');
exception
    when DUP_VAL_ON_INDEX then
        return;
end;
/
</pre>
</blockquote>
<p>Not only does Oracle allow you to do &#8220;insert ignore&#8221;, it provides you with fine grained control about exceptions &#8211; in this case, I am catching the case when a unique key (such as the primary key) is violated.  In his blog post, Hampus <a href="http://halisway.blogspot.com/2007/04/how-to-do-insert-ignore-in-oracle.html">recommends a similar approach</a> and also points out that you can use Oracle&#8217;s <a href="http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_9016.htm">MERGE</a> statement (which, incidentally, is on of my favorite statements!) for this purpose.</p>
<p>I guess the purpose of this post is to once again point out the inconsistency in how different databases implement standard SQL (I talked about this a little bit in a post about <a href="http://maggienelson.com/2009/02/the-meaning-of-keys/">The Meaning of Keys</a>).  When you see something that Oracle has and MySQL and vice versa is sometimes tied to this different approach.  I&#8217;m willing to concede that MySQL has some awesomeness, such as the kick-ass <a href="http://dev.mysql.com/doc/refman/4.1/en/group-by-functions.html#function_group-concat">GROUP_CONCAT</a> function.  But if you still feel like QQ&#8217;ing at Oracle (e.g. in comments on this blog post), fair warning, I will continue to defend it &#8211; I only ask that you QQ constructively!</p>
]]></content:encoded>
			<wfw:commentRss>http://maggienelson.com/2009/03/the-rules-of-software-engagement/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
