<?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>WEB-NES-BAY &#187; mysql</title>
	<atom:link href="http://webnesbay.com/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://webnesbay.com</link>
	<description>Learn Tips and tricks on Linux, Hacking, linux, PHP, Perl, Web, Hardware</description>
	<lastBuildDate>Sun, 11 Apr 2010 05:12:40 +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>Using Foriegn Keys in MySql with simple example</title>
		<link>http://webnesbay.com/using-foriegn-keys-in-mysql-with-simple-example/</link>
		<comments>http://webnesbay.com/using-foriegn-keys-in-mysql-with-simple-example/#comments</comments>
		<pubDate>Wed, 02 Sep 2009 03:55:11 +0000</pubDate>
		<dc:creator>WEBNESBAY</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[Auto Increment]]></category>
		<category><![CDATA[Banana]]></category>
		<category><![CDATA[Grapes]]></category>
		<category><![CDATA[High Volume]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Orange]]></category>
		<category><![CDATA[Orrange]]></category>
		<category><![CDATA[Previous Versions]]></category>
		<category><![CDATA[Referential Integrity]]></category>
		<category><![CDATA[Relationship]]></category>
		<category><![CDATA[Sec Records]]></category>
		<category><![CDATA[Species Code]]></category>
		<category><![CDATA[Species Table]]></category>
		<category><![CDATA[Table Fruits]]></category>
		<category><![CDATA[Two Tables]]></category>
		<category><![CDATA[Valid Species]]></category>
		<category><![CDATA[Zoo]]></category>

		<guid isPermaLink="false">http://webnesbay.com/?p=670</guid>
		<description><![CDATA[Referential integrity is usually implemented through the use of foreign keys. In previous versions the popular open-source RDBMS MySQL did not support foreign keys. However, given the high volume of user interest in this feature, later versions of MySQL implemented support for foreign keys through the InnoDB table engine. Consequently, maintaining referential integrity within the tables that make up a database is significantly simpler.
These are the following criteria to form a table with foriegn keys
1. Both tables must be of [...]


Related posts:<ol><li><a href='http://webnesbay.com/oracle-owns-mysql-but-this-is-open-source-code/' rel='bookmark' title='Permanent Link: Oracle Owns MySQL, But This Is Open Source Code'>Oracle Owns MySQL, But This Is Open Source Code</a></li>
<li><a href='http://webnesbay.com/list-extract-and-compact-simple-but-very-useful-functions-in-php/' rel='bookmark' title='Permanent Link: List Extract and Compact simple but very useful functions in php'>List Extract and Compact simple but very useful functions in php</a></li>
<li><a href='http://webnesbay.com/access-files-on-the-server-via-sql-injection-in-postgresql/' rel='bookmark' title='Permanent Link: Access files on the server via sql-injection in PostgreSQL'>Access files on the server via sql-injection in PostgreSQL</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Referential integrity is usually implemented through the use of foreign keys. In previous versions the popular open-source RDBMS MySQL did not support foreign keys. However, given the high volume of user interest in this feature, later versions of MySQL implemented support for foreign keys through the InnoDB table engine. Consequently, maintaining referential integrity within the tables that make up a database is significantly simpler.</p>
<p>These are the following criteria to form a table with foriegn keys</p>
<p>1. Both tables must be of the InnoDB table type.<br />
2. The fields used in the foreign key relationship must be indexed.<br />
3. The fields used in the foreign key relationship must be similar in data type.</p>
<p>Lets talk with anexample with foriegn keys with better understanding</p>
<p>The idea here is to link the two tables by the species code, so that only those entries in the zoo table which have a valid species code in the species table are accepted and saved to the database.</p>
<p>mysql&gt; CREATE TABLE Fruits (id TINYINT NOT NULL AUTO_INCREMENT,<br />
name VARCHAR(50) NOT NULL, PRIMARY KEY(id)) ENGINE=INNODB;<br />
Query OK, 0 rows affected (0.11 sec)</p>
<p>mysql&gt; INSERT INTO Fruits VALUES (1, &#8216;orange&#8217;), (2, &#8216;apple&#8217;),<br />
(3, &#8216;banana&#8217;), (4, &#8216;grapes&#8217;);<br />
Query OK, 4 rows affected (0.06 sec)<br />
Records: 4  Duplicates: 0  Warnings: 0</p>
<p>mysql&gt; CREATE TABLE basket (<br />
id INT(4) NOT NULL,<br />
name VARCHAR(50) NOT NULL,<br />
FK_Fruits TINYINT(4) NOT NULL,<br />
INDEX (FK_Fruits),<br />
FOREIGN KEY (FK_Fruits) REFERENCES Fruits (id),<br />
PRIMARY KEY(id)<br />
) ENGINE=INNODB;</p>
<p>Important: For non-InnoDB tables, the FOREIGN KEY clause is ignored.</p>
<p>As the above illustrates, a foreign key relationship now exists between the basket.species and Fruits.id. An entry in the basket table will be permitted only if the corresponding Basket.fruits field matches a value in the fruits.idfield. This is clearly visible in the following output, which demonstrates what happens when you attempt to enter a record for Orrange  with an invalid Fruits code:</p>
<p>mysql&gt; INSERT INTO Basket VALUES (1, &#8216;Orrange&#8217;, 5);<br />
ERROR 1216 (23000): Cannot add or update a child row: a foreign key<br />
constraint fails</p>
<p>Here, MySQL checks the Fruist table to see if the Fruits code exists and, finding that it does not, rejects the record. Contrast this with what happens when you enter the same record with a valid Fruits code (one that already exists in the Fruits table):</p>
<p>mysql&gt; INSERT INTO basket VALUES (1, &#8216;Orrange&#8217;, 3);<br />
Query OK, 1 row affected (0.06 sec)</p>
<p>Here, MySQL checks the Fruits table to see if the Fruits code exists and, finding that it does, permits the record to be saved to the basket table.</p>
<p>Adding and deleting a foriegn Key</p>
<p>To delete a foreign key relationship, first use the SHOW CREATE TABLE command to find out InnoDB&#8217;s internal label for the field.</p>
<p>+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
| Table | Create Table                                      |<br />
+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
| zoo   | CREATE TABLE `basket` (<br />
`id` int(4) NOT NULL default &#8216;0&#8242;,<br />
`name` varchar(50) NOT NULL default &#8221;,<br />
`FK_Fruits` tinyint(4) NOT NULL default &#8216;0&#8242;,<br />
KEY `FK_Fruits` (`FK_Fruits`),<br />
CONSTRAINT `basket_ibfk_1` FOREIGN KEY (`FK_Fruits`)<br />
REFERENCES `Fruits` (`id`)<br />
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |<br />
+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+</p>
<p>And then use the ALTER TABLE command with the DROP FOREIGN KEY clause, as below:</p>
<p>mysql&gt; ALTER TABLE basket DROP FOREIGN KEY basket_ibfk_1;<br />
Query OK, 1 row affected (0.11 sec)<br />
Records: 1  Duplicates: 0  Warnings: 0</p>
<p>To add a foreign key to an existing table, use the ALTER TABLE command with an ADD FOREIGN KEY clause to define the appropriate field as a foreign key:</p>
<p>mysql&gt; ALTER TABLE basket ADD FOREIGN KEY<br />
(FK_Fruits) REFERENCES Fruits (id);<br />
Query OK, 1 rows affected (0.11 sec)<br />
Records: 1  Duplicates: 0  Warnings: 0</p>
<p>From the above example, foriegn key plays a mojot role in handling the data errors in the run time. Also this is also help ful in handling the data redundancy.</p>
<p>Please post your comments if you have any queries.</p>
<p>Refernce: <a href="http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html">dev.mysql.com</a></p>


<p>Related posts:<ol><li><a href='http://webnesbay.com/oracle-owns-mysql-but-this-is-open-source-code/' rel='bookmark' title='Permanent Link: Oracle Owns MySQL, But This Is Open Source Code'>Oracle Owns MySQL, But This Is Open Source Code</a></li>
<li><a href='http://webnesbay.com/list-extract-and-compact-simple-but-very-useful-functions-in-php/' rel='bookmark' title='Permanent Link: List Extract and Compact simple but very useful functions in php'>List Extract and Compact simple but very useful functions in php</a></li>
<li><a href='http://webnesbay.com/access-files-on-the-server-via-sql-injection-in-postgresql/' rel='bookmark' title='Permanent Link: Access files on the server via sql-injection in PostgreSQL'>Access files on the server via sql-injection in PostgreSQL</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://webnesbay.com/using-foriegn-keys-in-mysql-with-simple-example/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Oracle Owns MySQL, But This Is Open Source Code</title>
		<link>http://webnesbay.com/oracle-owns-mysql-but-this-is-open-source-code/</link>
		<comments>http://webnesbay.com/oracle-owns-mysql-but-this-is-open-source-code/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 06:26:05 +0000</pubDate>
		<dc:creator>WEBNESBAY</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[oracle]]></category>

		<guid isPermaLink="false">http://webnesbay.com/175/oracle-owns-mysql-but-this-is-open-source-code/</guid>
		<description><![CDATA[
Oracle and MySQL are the favorite databases of developers who use the Eclipse open source programmers workbench. That&#8217;s no surprise, I thought. Developers like to develop in free MySQL and deploy in Oracle, right? Actually, Oracle and MySQL are their two favorite deployment databases, contrary to what I would have expected.
Not only are Eclipse users deploying both MySQL and Oracle, they&#8217;re deploying the two equally, while I would have given an advantage to Oracle.
Instead, the edge goes to MySQL. The [...]


Related posts:<ol><li><a href='http://webnesbay.com/using-foriegn-keys-in-mysql-with-simple-example/' rel='bookmark' title='Permanent Link: Using Foriegn Keys in MySql with simple example'>Using Foriegn Keys in MySql with simple example</a></li>
<li><a href='http://webnesbay.com/tips-to-protect-databases-from-malacious-attacks/' rel='bookmark' title='Permanent Link: Tips to protect databases from malacious attacks'>Tips to protect databases from malacious attacks</a></li>
<li><a href='http://webnesbay.com/google-waves-architecture/' rel='bookmark' title='Permanent Link: Google waves architecture'>Google waves architecture</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><span style="font-family: geneva; font-size: 12px;"></p>
<p style="font-family: Verdana,Arial,sans-serif; font-size: 11px; font-style: normal; font-weight: normal; color: #000000;">Oracle<span> </span>and MySQL are the favorite databases of developers who use the Eclipse open source programmers workbench. That&#8217;s no surprise, I thought. Developers like to develop in free MySQL and deploy in Oracle, right? Actually, Oracle and MySQL are their two favorite deployment databases, contrary to what I would have expected.</p>
<p style="font-family: Verdana,Arial,sans-serif; font-size: 11px; font-style: normal; font-weight: normal; color: #000000;">Not only are Eclipse users deploying both MySQL and Oracle, they&#8217;re deploying the two equally, while I would have given an advantage to Oracle.</p>
<p>Instead, the edge goes to MySQL. The Eclipse site survey showed that 27.7% deploy in MySQL; 27.3% in Oracle. In acquiring MySQL&#8217;s new owner, Sun, Oracle is also acquiring its own largest database competitor in the enterprise Java community. Oracle plus MySQL add up to 55% of deployments among the Eclipse users.
</p>
<p style="font-family: Verdana,Arial,sans-serif; font-size: 11px; font-style: normal; font-weight: normal; color: #000000;">There&#8217;s two arguments against taking the 55% too seriously.</p>
<p style="font-family: Verdana,Arial,sans-serif; font-size: 11px; font-style: normal; font-weight: normal; color: #000000;">As you look at database deployments among the larger companies in this sample, the MySQL share drops and Oracle&#8217;s dominant share of newly deployed databases is weakened&#8211;though by less than I would have thought&#8211;by the presence of IBM. IBM&#8217;s DB2 goes from 6.2% of all users to 10.7% among the larger users. But that&#8217;s still less than 11% in the face of Oracle being deployed among 33.5% of this group, with MySQL being deployed by another 11.6%. Oracle&#8217;s combined share among larger Eclipse users is 45.1%.</p>
<p style="font-family: Verdana,Arial,sans-serif; font-size: 11px; font-style: normal; font-weight: normal; color: #000000;">Another argument against worrying that 55% is too much, however, is that MySQL remains open source code, a fact that&#8217;s hard to reverse. If current MySQL users don&#8217;t like what&#8217;s happening with the code, they can form a new MySQL project and back it.</p>
<p style="font-family: Verdana,Arial,sans-serif; font-size: 11px; font-style: normal; font-weight: normal; color: #000000;">That means, I think, that MySQL developers are a prize that Oracle will soon start angling for. I don&#8217;t think Oracle is likely to disturb MySQL&#8217;s existing code direction, though I question how willing it will be to encourage it to become a full fledged, transaction database, something that it isn&#8217;t now. MySQL founder Monty Widenius wants to see it go in that direction and left Sun to push the MariaDB, a version of MySQL capable of storing transactions.</p>
<p style="font-family: Verdana,Arial,sans-serif; font-size: 11px; font-style: normal; font-weight: normal; color: #000000;">He&#8217;s also founded the Open Database Alliance, a watchdog meant to safeguard the core MySQL system in the face of &#8220;uncertainties&#8221; over its second round of new ownership.</p>
<p style="font-family: Verdana,Arial,sans-serif; font-size: 11px; font-style: normal; font-weight: normal; color: #000000;">There&#8217;s both drama and comedy in this. If the original authors of MySQL were so concerned about its future, why did they agree to sell to Sun in the first place? Having cashed Sun&#8217;s check, can they still claim moral authority over the code? I doubt it, but this is open source and we are untested ground. I may wake up some morning and find that Monty does indeed still own a significant share of MySQL, even though it&#8217;s passed into the hands of new owners twice.</p>
<p style="font-family: Verdana,Arial,sans-serif; font-size: 11px; font-style: normal; font-weight: normal; color: #000000;">So what will Oracle do with MySQL under the watchful gaze of the Open Database Alliance?</p>
<p style="font-family: Verdana,Arial,sans-serif; font-size: 11px; font-style: normal; font-weight: normal; color: #000000;">My suspicion is that Oracle will keep its hands off, so much so that MySQL may suffer from benign neglect. Who&#8217;s to know if MySQL developers get reassigned within that 40,000 developer stable to redoing PeopleSoft applications or cobbling together code in Oracle middleware&#8217;s vasty keep? MySQL salesmen might be informed they&#8217;re too specialized now that they&#8217;re inside Oracle and be given a broader product list to sell. Not doing so well with Oracle 11g or Fusion middleware? Who will protest if their ranks thin out?</p>
<p style="font-family: Verdana,Arial,sans-serif; font-size: 11px; font-style: normal; font-weight: normal; color: #000000;">What exactly can the Open Database Alliance do about benign neglect, if it occurs?<span> </span></p>
<p>Meanwhile, Oracle could boast of having MySQL uppermost in its thoughts as it brings out development tools, designed to work with either Oracle or MySQL. In its heart of hearts, it will hope to convert some MySQL users to Oracle in the future by making it easy to make the switch, but it doesn&#8217;t have to declare it on day one.</p>
<p style="font-family: Verdana,Arial,sans-serif; font-size: 11px; font-style: normal; font-weight: normal; color: #000000;">These tools might be provisioned to generate linkages to Oracle middleware, so that the Fusion product set could be used easily with either MySQL or Oracle databases. Even if the MySQL users never convert to 11g, getting 55% of the middleware market isn&#8217;t all bad as a consolation prize.</p>
<p>But the Eclipse survey makes me think that there are implications to Oracle&#8217;s ownership of MySQL that I hadn&#8217;t considered before. What&#8217;s the responsibility of an open source code owner? Is it obligated to honor previous initiatives that might bring the code into more direct competition with its own products?</p>
<p>And who owns open source code, a question that can&#8217;t be answered by simply examining who&#8217;s signing the checks. For the ownership to be honored, the community using the code has to recognize the leadership of the owner. If Oracle aggressively snipped off MySQL&#8217;s next round of improvements, I think it&#8217;s possible that ownership would transfer outside of Oracle to a new project, as the code forked.
</p>
<p style="font-family: Verdana,Arial,sans-serif; font-size: 11px; font-style: normal; font-weight: normal; color: #000000;">Before, Widenius was a gifted programmer, a trusted figure to hundreds of thousands of MySQL users and pure of heart in his respect for the code, whether it was being handled by an independent MySQL AB or inside of Sun. Now he has a significant share of Sun&#8217;s $1 billion check in his pocket, which only makes him more dangerous, from Oracle&#8217;s point of view.</p>
<p style="font-family: Verdana,Arial,sans-serif; font-size: 11px; font-style: normal; font-weight: normal; color: #000000;">The Eclipse survey convinces me that MySQL is a significant asset that can be won or lost by any of its recent or current owners. It is open source code inside a large, proprietary company. Whatever you thought the rules of business were, be prepared to rewrite them as this drama unfolds.</p>
<p></span></p>


<p>Related posts:<ol><li><a href='http://webnesbay.com/using-foriegn-keys-in-mysql-with-simple-example/' rel='bookmark' title='Permanent Link: Using Foriegn Keys in MySql with simple example'>Using Foriegn Keys in MySql with simple example</a></li>
<li><a href='http://webnesbay.com/tips-to-protect-databases-from-malacious-attacks/' rel='bookmark' title='Permanent Link: Tips to protect databases from malacious attacks'>Tips to protect databases from malacious attacks</a></li>
<li><a href='http://webnesbay.com/google-waves-architecture/' rel='bookmark' title='Permanent Link: Google waves architecture'>Google waves architecture</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://webnesbay.com/oracle-owns-mysql-but-this-is-open-source-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
