
<?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>doOriented.com &#187; Database</title>
	<atom:link href="http://www.dooriented.com/blog/category/database/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dooriented.com/blog</link>
	<description>Less words, more code</description>
	<lastBuildDate>Thu, 25 Jun 2009 01:23:44 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>MySQL multirow inserts</title>
		<link>http://www.dooriented.com/blog/2009/05/03/mysql-multirow-inserts/</link>
		<comments>http://www.dooriented.com/blog/2009/05/03/mysql-multirow-inserts/#comments</comments>
		<pubDate>Sat, 02 May 2009 21:41:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Database]]></category>

		<guid isPermaLink="false">http://www.dooriented.com/blog/?p=19</guid>
		<description><![CDATA[




I was surprised to see how few people know that in MySQL you can do :
INSERT INTO tbl_01(id, name) VALUES (1, &#8216;One&#8217;)
INSERT INTO tbl_01(id, name) VALUES(2, &#8216;Two&#8217;)





But also
INSERT INT tbl_01(id, name) VALUES
(1, &#8216;One&#8217;), (2, &#8216;Two&#8217;)
In practice it is very useful.





]]></description>
			<content:encoded><![CDATA[<p>I was surprised to see how few people know that in MySQL you can do :</p>
<p>INSERT INTO tbl_01(id, name) VALUES (1, &#8216;One&#8217;)</p>
<p>INSERT INTO tbl_01(id, name) VALUES(2, &#8216;Two&#8217;)</p>
<p>But also</p>
<p>INSERT INT tbl_01(id, name) VALUES</p>
<p>(1, &#8216;One&#8217;), (2, &#8216;Two&#8217;)</p>
<p>In practice it is very useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dooriented.com/blog/2009/05/03/mysql-multirow-inserts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL autoincrement vs Oracle sequence</title>
		<link>http://www.dooriented.com/blog/2009/05/03/mysql-autoincrement-vs-oracle-sequence/</link>
		<comments>http://www.dooriented.com/blog/2009/05/03/mysql-autoincrement-vs-oracle-sequence/#comments</comments>
		<pubDate>Sat, 02 May 2009 21:35:28 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Database]]></category>

		<guid isPermaLink="false">http://www.dooriented.com/blog/?p=14</guid>
		<description><![CDATA[In Oracle, sequences (often called autonumber) are used to maintain a unique series of numbers for an id field. Sequences are independent of any table hence they can be used to keep a value unique across a number of tables. Sequences actually do not have to be used in relationship with any table.
The syntax for [...]]]></description>
			<content:encoded><![CDATA[<p>In Oracle, sequences (often called autonumber) are used to maintain a unique series of numbers for an id field. Sequences are independent of any table hence they can be used to keep a value unique across a number of tables. Sequences actually do not have to be used in relationship with any table.</p>
<p>The syntax for creating a sequence is :</p>
<p>CREATE SEQUENCE sequence_name<br />
MINVALUE value<br />
MAXVALUE value<br />
START WITH value<br />
INCREMENT BY value<br />
CACHE value;</p>
<p>If you omit the MAXVALUE, it will default to</p>
<p>MAXVALUE 999999999999999999999999999</p>
<p>To retrieve the next value from the sequence, <em>nextval </em>is to be used :</p>
<p>sequence_name.nextval</p>
<p>The <em>nextval </em>statement needs to be used in an SQL statement, for instance :</p>
<p>INSERT INTO tbl_name(tbl_id, tbl_col_name)<br />
VALUES(sequence_name.nextval, &#8216;Name&#8217;);</p>
<p>The CACHE option specifies how many values would be stored in memory for faster access. It sounds good, but if for some reason a system failure occurs, all cached sequence values would be &#8220;lost&#8221; &#8211; when the system is be back up, the sequence will use the next value starting from MINVALUE + CACHE. NOCACHE sacrifices some performance, but you won&#8217;t get a &#8220;gap&#8221; in the values.</p>
<p>Oracle DOES NOT implement any column with autoincrement property. In turn, MySQL does not support sequences. MySQL uses autoincrement,applied to the primary key during table creation :</p>
<p>create table tbl_01 (id int primary key auto_increment, name varchar(100));</p>
<p>The value for the primary key will be assigned automatically, if during an insert there is no value manually assigned to the id column.</p>
<p>Note that the &#8220;sequence&#8221; will start from the highest value. If we manually insert a record with a number for the id higher than the maximum id in that table, the next insert with no value for the id will automatically assign that max value incremented.</p>
<p>For example suppose you have the following data in the table:</p>
<p>id  name</p>
<p>1   One</p>
<p>2  Two</p>
<p>3  Three</p>
<p>You do an insert like this :</p>
<p>INSERT INTO tbl_01(id, name) VALUES (10, &#8216;Ten&#8217;);</p>
<p>You will end up with the following table :</p>
<p>id  name</p>
<p>1   One</p>
<p>2  Two</p>
<p>3  Three</p>
<p>10 Ten</p>
<p>When you execute the following SQL:</p>
<p>INSERT INTO TABLE tbl_01(name) VALUES (&#8217;Next&#8217;);</p>
<p>You will end up with :</p>
<p>id  name</p>
<p>1   One</p>
<p>2  Two</p>
<p>3  Three</p>
<p>10 Ten</p>
<p>11 Next</p>
<p>You can insert record with a value for the id lower than the MAX(id) and that will not affect the next autoincrement value. It just has to follow the normal rules for the primary key (no duplicates).</p>
<p>Also if all the records are deleted from the table, the autoincrement is <em>not affected</em> (it will continue to assign the incremented MAX(id) based on the values that were previously in the table). In order to &#8220;reset the sequence&#8221; a the table must be truncated :</p>
<p>truncate table tbl_01</p>
<p>Now the first automatically generated value for the id will be 1. You can achieve the same by :</p>
<p>ALTER TABLE tbl_01 auto_increment=<em>value</em></p>
<p>Compared to Oracle, MySQL is pretty straightforward, but does have its [big] limitations: it cannot be used across multiple tables and you cannot set different increment values.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dooriented.com/blog/2009/05/03/mysql-autoincrement-vs-oracle-sequence/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>MySQL case sensitivity</title>
		<link>http://www.dooriented.com/blog/2009/05/02/mysql-case-sensitivity/</link>
		<comments>http://www.dooriented.com/blog/2009/05/02/mysql-case-sensitivity/#comments</comments>
		<pubDate>Sat, 02 May 2009 17:18:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Database]]></category>

		<guid isPermaLink="false">http://www.dooriented.com/blog/?p=11</guid>
		<description><![CDATA[Consider a table tbl_01 containing a column Name and consider the following query :
SELECT * FROM tbl_01 WHERE name = &#8216;paul&#8217;
In Oracle this query would return only the rows containing &#8216;paul&#8217; in the column name, because Oracle is case sensitive.
MySQL is not, so the same query would return rows containing &#8216;Paul&#8217;, &#8216;paul&#8217;, &#8216;pAul&#8217;, etc. In [...]]]></description>
			<content:encoded><![CDATA[<p>Consider a table tbl_01 containing a column Name and consider the following query :</p>
<p>SELECT * FROM tbl_01 WHERE name = &#8216;paul&#8217;</p>
<p>In Oracle this query would return <em>only</em> the rows containing &#8216;paul&#8217; in the column name, because Oracle is case sensitive.</p>
<p>MySQL is not, so the same query would return rows containing &#8216;Paul&#8217;, &#8216;paul&#8217;, &#8216;pAul&#8217;, etc. In order to force MySQL to check for the exact case, the keyword <em><strong>binary</strong></em> has to be used :</p>
<p>SELECT * FROM tbl_01 WHERE binary name = &#8220;paul&#8221;</p>
<p>There is also an alternative to this &#8211; making a column case sensitive on table creation:</p>
<p>CREATE TABLE tbl_01 (name varchar(100) binary);</p>
<p>Now the select on name cares for the way the name is written.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dooriented.com/blog/2009/05/02/mysql-case-sensitivity/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
