<?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>Johan Känngård &#187; SQL</title>
	<atom:link href="http://johankanngard.net/tag/sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://johankanngard.net</link>
	<description>Useful tips for developers</description>
	<lastBuildDate>Thu, 19 May 2011 18:40:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>MySQL Commands Cheat Sheet</title>
		<link>http://johankanngard.net/2008/07/31/mysql-commands-cheat-sheet/</link>
		<comments>http://johankanngard.net/2008/07/31/mysql-commands-cheat-sheet/#comments</comments>
		<pubDate>Thu, 31 Jul 2008 12:03:48 +0000</pubDate>
		<dc:creator>Johan Känngård</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://johankanngard.net/?p=255</guid>
		<description><![CDATA[Another memory-dump. The manual contains more information (that&#8217;s a surprise :-). mysql> delete from TABLE where id=X Removes the specified row mysql> describe TABLE; Shows the structure of the specified table mysql> select * from TABLE; Shows all rows in the specified table :-O mysql> show procedure status; Shows stored procedures mysql> show table status; [...]]]></description>
			<content:encoded><![CDATA[<p>
Another memory-dump. The <a href="http://dev.mysql.com/doc/#manual">manual</a> contains more information (that&#8217;s a surprise :-).
</p>
<dl>
<dt>mysql> delete from TABLE where id=X</dt>
<dd>Removes the specified row</dd>
<dt>mysql> describe TABLE;</dt>
<dd>Shows the structure of the specified table</dd>
<dt>mysql> select * from TABLE;</dt>
<dd>Shows all rows in the specified table :-O</dd>
<dt>mysql> show procedure status;</dt>
<dd>Shows stored procedures</dd>
<dt>mysql> show table status;</dt>
<dd>Shows tables in current database</dd>
<dt>mysql> use MYDATABASE;</dt>
<dd>Changes the database to act on</dd>
</dl>
]]></content:encoded>
			<wfw:commentRss>http://johankanngard.net/2008/07/31/mysql-commands-cheat-sheet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL 5 Stored Procedures Cheat Sheet</title>
		<link>http://johankanngard.net/2007/07/05/mysql-5-stored-procedures-cheat-sheet/</link>
		<comments>http://johankanngard.net/2007/07/05/mysql-5-stored-procedures-cheat-sheet/#comments</comments>
		<pubDate>Thu, 05 Jul 2007 10:37:57 +0000</pubDate>
		<dc:creator>Johan Känngård</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://johankanngard.net/2007/07/05/mysql-5-stored-procedures-cheat-sheet/</guid>
		<description><![CDATA[I will add more when I stumble upon commands I can&#8217;t remember the syntax of. To list all stored procedures: mysql> SHOW PROCEDURE STATUS; Example output (with cropped dates and times for readable table): Db Name Type Definer Modified Created Security_type Comment mydb store_user PROCEDURE root 2007-0.. 2007-0.. DEFINER mydb store_cart PROCEDURE root 2007-0.. 2007-0.. [...]]]></description>
			<content:encoded><![CDATA[<p>
I will add more when I stumble upon commands I can&#8217;t remember the syntax of.
</p>
<h2>To list all stored procedures:</h2>
<p><code><br />
mysql> SHOW PROCEDURE STATUS;<br />
</code><br />
Example output (with cropped dates and times for readable table):</p>
<table>
<thead>
<tr>
<th>Db</th>
<th>Name</th>
<th>Type</th>
<th>Definer</th>
<th>Modified</th>
<th>Created</th>
<th>Security_type</th>
<th>Comment</th>
</tr>
</thead>
<tbody>
<tr>
<td>mydb</td>
<td>store_user</td>
<td>PROCEDURE</td>
<td>root</td>
<td>2007-0..</td>
<td>2007-0..</td>
<td>DEFINER</td>
<td></td>
</tr>
<tr>
<td>mydb</td>
<td>store_cart</td>
<td>PROCEDURE</td>
<td>root</td>
<td>2007-0..</td>
<td>2007-0..</td>
<td>DEFINER</td>
<td></td>
</tr>
<tr>
<td>mydb</td>
<td>store_settings</td>
<td>PROCEDURE</td>
<td>root</td>
<td>2007-0..</td>
<td>2007-0..</td>
<td>DEFINER</td>
<td></td>
</tr>
</tbody>
</table>
<p><script type="text/javascript"><!--
google_ad_client = "pub-8220767383302774";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text";
google_ad_channel ="";
google_color_border = "CCCCCC";
google_color_bg = "FFFFFF";
google_color_link = "000000";
google_color_url = "666666";
google_color_text = "333333";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><br />
<span id="more-134"></span></p>
<h2>To create a new procedure</h2>
<p><code><br />
mysql> DELIMITER $$<br />
mysql> CREATE PROCEDURE adduser(IN username VARCHAR(32), IN emailaddress VARCHAR(32))<br />
BEGIN<br />
	INSERT INTO users VALUES (username, emailaddress);<br />
END<br />
$$<br />
</code></p>
<h2>To show a stored procedure</h2>
<p><code><br />
mysql> SHOW CREATE PROCEDURE `userdb`.`adduser`\\\\G<br />
</code><br />
Example output:<br />
<code><br />
*************************** 1. row ***************************<br />
       Procedure: adduser<br />
        sql_mode:<br />
Create Procedure: CREATE DEFINER=`root`@`localhost` PROCEDURE `adduser`(IN username varchar(32), IN emailaddress(32))<br />
BEGIN<br />
	INSERT INTO users VALUES (username, emailaddress);<br />
END<br />
1 row in set (0.00 sec)<br />
</code></p>
<h2>To call a stored procedure from Java</h2>
<p><code><br />
Connection con = DriverManager.getConnection(url, user, password);<br />
CallableStatement statement = con.prepareCall(\\\"{call userdb.adduser(?, ?)}\\\");<br />
int i = 0;<br />
statement.setString(i++, \\\"myuser\\\");<br />
statement.setString(i++, \\\"myuser@spammealot.com\\\");<br />
statement.execute();<br />
</code><br />
For this to work you must give the user SELECT privilege to the proc table in the MySQL database, where the stored procedures are stored. Do it like this:<br />
<code><br />
GRANT SELECT ON `mysql`.`proc` TO \\\'mysqluser\\\'@\\\'myhost\\\';<br />
</code><br />
<ins datetime="2008-07-31T12:04:20+00:00">For a list of more commands, see my <a href="http://johankanngard.net/2008/07/31/mysql-commands-cheat-sheet/">MySQL Commands Cheat Sheet</a>.</ins></p>
]]></content:encoded>
			<wfw:commentRss>http://johankanngard.net/2007/07/05/mysql-5-stored-procedures-cheat-sheet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

