<?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>PersonalBlog &#187; MySQL</title>
	<atom:link href="http://arimita.web.id/category/it/mysql-it/feed/" rel="self" type="application/rss+xml" />
	<link>http://arimita.web.id</link>
	<description>Just another personal weblog</description>
	<lastBuildDate>Mon, 19 Jul 2010 08:31:10 +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>TRIGGER</title>
		<link>http://arimita.web.id/2010/06/trigger/</link>
		<comments>http://arimita.web.id/2010/06/trigger/#comments</comments>
		<pubDate>Fri, 18 Jun 2010 03:04:05 +0000</pubDate>
		<dc:creator>mythworks</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[delete trigger]]></category>
		<category><![CDATA[insert trigger]]></category>
		<category><![CDATA[privilege]]></category>
		<category><![CDATA[trigger]]></category>
		<category><![CDATA[trigger mysql]]></category>
		<category><![CDATA[update trigger]]></category>

		<guid isPermaLink="false">http://arimita.web.id/?p=242</guid>
		<description><![CDATA[Trigger means procedural code that is automatically executed in response to certain events on a particular table or view in a database. Create trigger requires the trigger privilege for the table associated with the trigger. 
TRIGGER syntax:
CREATE TRIGGER name
[BEFORE &#124; AFTER] [INSERT &#124; UPDATE &#124; DELETE]
ON tablename
FOR EACH ROW statement
BEFORE or AFTER on trigger is [...]]]></description>
			<content:encoded><![CDATA[<p>Trigger means procedural code that is automatically executed in response to certain events on a particular table or view in a database. Create trigger requires the trigger privilege for the table associated with the trigger. </p>
<p><strong>TRIGGER syntax:</strong></p>
<p>CREATE TRIGGER name<br />
[BEFORE | AFTER] [INSERT | UPDATE | DELETE]<br />
ON tablename<br />
FOR EACH ROW statement</p>
<p>BEFORE or AFTER on trigger is action time to indicate when trigger activities statement activated.<br />
INSERT or UPDATE or DELETE is event indicates the kind of statement that activates the trigger.</p>
<p>How to drop the TRIGGER ?, use DROP TRIGGER order following with table name and trigger name. And the syntax is like this:</p>
<p><strong>DROP TRIGGER tablename.triggername;</strong></p>
<p>Here they are the example case use trigger:<br />
<strong>For inserting prosess:</strong></p>
<pre class="brush: sql;">
CREATE trigger tr_input before INSERT ON user
FOR each
ROW
BEGIN
INSERT INTO master_user( id, name, pass )
VALUES (
NEW.id, NEW.name, NEW.pass
);
END$$
</pre>
<p><strong>For updating process:</strong></p>
<pre class="brush: sql;">
CREATE trigger tr_update before UPDATE ON user
FOR each
ROW
BEGIN
UPDATE master_user set id=new.id, name=new.name, pass=new.pass
where id=old.id;
END$$
</pre>
<p><strong>For deleting process:</strong></p>
<pre class="brush: sql;">
CREATE trigger tr_delete before DELETE ON user
FOR each
ROW
BEGIN
DELETE from master_user where id=old.id;
END$$
</pre>
<p>The SELECT privilege for the subject table if references to table colums occur via OLD.col_name or NEW.col_name<br />
The UPDATE privilege for the subject table columns are targets of SET NEW.col_name=value assignment.</p>
<p>Note: in this case I use two table user and master_user. And the scenario is when I input some data or something else into user which automatically updated into master_user.</p>
]]></content:encoded>
			<wfw:commentRss>http://arimita.web.id/2010/06/trigger/feed/</wfw:commentRss>
		<slash:comments>139</slash:comments>
		</item>
		<item>
		<title>CREATE PROCEDURE and CREATE FUNCTION</title>
		<link>http://arimita.web.id/2010/06/create-procedure-and-create-function/</link>
		<comments>http://arimita.web.id/2010/06/create-procedure-and-create-function/#comments</comments>
		<pubDate>Tue, 15 Jun 2010 07:13:59 +0000</pubDate>
		<dc:creator>mythworks</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[create function.]]></category>
		<category><![CDATA[create procedure]]></category>
		<category><![CDATA[function syntax]]></category>
		<category><![CDATA[procedur syntax]]></category>

		<guid isPermaLink="false">http://arimita.web.id/?p=232</guid>
		<description><![CDATA[CREATE PROCEDURE syntax
CREATE
[DEFINER = { user &#124; CURRENT_USER }]
PROCEDURE sp_name ([proc_parameter[,...]])
[characteristic ...] routine_body
proc_parameter:
[ IN &#124; OUT &#124; INOUT ] param_name type
CREATE FUNCTION syntax
CREATE
[DEFINER = { user &#124; CURRENT_USER }]
FUNCTION sp_name ([func_parameter[,...]])
RETURNS type
[characteristic ...] routine_body
func_parameter:
param_name type
CREATE PROCEDURE and CREATE FUNCTION require the CREATE ROUTINE privilege. They might also require the SUPER privilege, depending on the DEFINER [...]]]></description>
			<content:encoded><![CDATA[<p><strong>CREATE PROCEDURE syntax</strong><br />
CREATE<br />
[DEFINER = { user | CURRENT_USER }]<br />
PROCEDURE sp_name ([proc_parameter[,...]])<br />
[characteristic ...] routine_body</p>
<p>proc_parameter:<br />
[ IN | OUT | INOUT ] param_name type</p>
<p><strong>CREATE FUNCTION syntax</strong><br />
CREATE<br />
[DEFINER = { user | CURRENT_USER }]<br />
FUNCTION sp_name ([func_parameter[,...]])<br />
RETURNS type<br />
[characteristic ...] routine_body</p>
<p>func_parameter:<br />
param_name type</p>
<p>CREATE PROCEDURE and CREATE FUNCTION require the CREATE ROUTINE privilege. They might also require the SUPER privilege, depending on the DEFINER value.</p>
<p><strong>DROP PROCEDURE and DROP FUNCTION Syntax:</strong> this statement is used to drop a stored procedure or function.</p>
<p>DROP {PROCEDURE | FUNCTION} [IF EXISTS] procedure_or_function_name</p>
<p>Specifying a parameter as IN, OUT, or INOUT is valid only for a PROCEDURE. For a FUNCTION, parameters are always regarded as IN parameters. An IN parameter passes a value into a procedure. An OUT parameter passes a value from the procedure back to the caller. Its initial value is NULL within the procedure, and its value is visible to the caller when the procedure returns. An INOUT parameter is initialized by the caller, can be modified by the procedure, and any change made by the procedure is visible to the caller when the procedure returns.<br />
Lets see a simple stored procedure using OUT parameter:</p>
<pre class="brush: sql;">
CREATE PROCEDURE jumlah( out juml int ) BEGIN SELECT count( * )
INTO juml
FROM FUNCTIONS;
END
</pre>
<p>Note: The example uses the mysql client delimiter command to change the statement delimiter from ; to // while the procedure is being defined. This allows the ; delimiter used in the procedure body to be passed through to the server rather than being interpreted by mysql itself.<br />
And now how to CALL the procedure? Lets see this query:</p>
<pre class="brush: sql;">
CALL jumlah(@a);
SELECT @a ;
</pre>
<p>If you want to see the that procedure is exists on your server, you can try to Export as a sql and check the structure especially Add CREATE PROCEDURE / FUNCTION. On the bottom you will see the procedure you have been created:<br />
&#8211;<br />
&#8211; Procedures<br />
&#8211;<br />
DELIMITER $$<br />
&#8211;<br />
CREATE DEFINER=`root`@`localhost` PROCEDURE `jumlah`( out juml int )<br />
BEGIN SELECT count( * )<br />
INTO juml<br />
FROM FUNCTIONS;<br />
END$$</p>
<p>&#8211;<br />
DELIMITER ;<br />
&#8211;</p>
<p>And then the syntax to drop the procedure if you want to trash it:<br />
DROP PROCEDURE IF EXISTS jumlah</p>
<p>Lets see a simple function:</p>
<pre class="brush: sql;">
CREATE FUNCTION fungsi(
aCHAR( 10 )
) RETURNS CHAR( 20 ) DETERMINISTIC RETURN CONCAT( 'Fungsi, ', a, '.' ) ;
</pre>
<p>Then try to execute that query like this to see the result:</p>
<pre class="brush: sql;">
SELECT fungsi('test only');
</pre>
<p>Like procedure above you can see the function by Export as sql and the bottom look view:</p>
<p>CREATE DEFINER=`root`@`localhost` FUNCTION `fungsi`(a CHAR(10)) RETURNS char(20) CHARSET latin1<br />
DETERMINISTIC<br />
RETURN CONCAT(&#8216;Fungsi, &#8216;,a,&#8217;.')</p>
<p>And then the syntax to drop the procedure if you want to trash it:</p>
<pre class="brush: sql;">
DROP FUNCTION IF EXISTS fungsi
</pre>
<p>Well improve your self with aother case and develop yours.</p>
]]></content:encoded>
			<wfw:commentRss>http://arimita.web.id/2010/06/create-procedure-and-create-function/feed/</wfw:commentRss>
		<slash:comments>99</slash:comments>
		</item>
		<item>
		<title>Regular Expressions</title>
		<link>http://arimita.web.id/2010/06/regular-expressions/</link>
		<comments>http://arimita.web.id/2010/06/regular-expressions/#comments</comments>
		<pubDate>Tue, 15 Jun 2010 06:43:55 +0000</pubDate>
		<dc:creator>mythworks</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[regexp]]></category>
		<category><![CDATA[regular expression]]></category>

		<guid isPermaLink="false">http://arimita.web.id/?p=228</guid>
		<description><![CDATA[A regular expression describes a set of strings. A regular expressions for the REGEXP operator may use any of the following special characters and constructs:

.     match any character (including carriage return and new line)

SELECT function_name
FROM `functions`
WHERE function_name
REGEXP 'anchor..'


^     match the beginning of a string

SELECT function_name
FROM `functions`
WHERE function_name
REGEXP [...]]]></description>
			<content:encoded><![CDATA[<p>A regular expression describes a set of strings. A regular expressions for the REGEXP operator may use any of the following special characters and constructs:</p>
<ul>
<li><strong>.</strong>     match any character (including carriage return and new line)
<pre class="brush: sql;">
SELECT function_name
FROM `functions`
WHERE function_name
REGEXP 'anchor..'
</pre>
</li>
<li><strong>^</strong>     match the beginning of a string
<pre class="brush: sql;">
SELECT function_name
FROM `functions`
WHERE function_name
REGEXP '^a';
</pre>
</li>
<li><strong>$</strong>	    match the end of a string
<pre class="brush: sql;">
SELECT function_name
FROM `functions`
WHERE function_description
REGEXP 't$';
</pre>
</li>
<li><strong>[characters]</strong>	    match any characters or using range
<pre class="brush: sql;">
SELECT function_name
FROM `functions`
WHERE function_name
REGEXP '^[a-d]';
</pre>
</li>
</ul>
<p>Still using function table, let’s see the other developing using regex.<br />
To view function_name which has 4 characters:</p>
<pre class="brush: sql;">
SELECT function_name
FROM `functions`
WHERE function_name
REGEXP '^....$';
</pre>
<p>Or we can write like this:</p>
<pre class="brush: sql;">
SELECT function_name
FROM `functions`
WHERE function_name
REGEXP '^.{4}$';
</pre>
<p>Hmm I think is enough for introduction of REGEXP <img src='http://arimita.web.id/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . </p>
]]></content:encoded>
			<wfw:commentRss>http://arimita.web.id/2010/06/regular-expressions/feed/</wfw:commentRss>
		<slash:comments>52</slash:comments>
		</item>
		<item>
		<title>LIKE and NOT LIKE</title>
		<link>http://arimita.web.id/2010/06/like-and-not-like/</link>
		<comments>http://arimita.web.id/2010/06/like-and-not-like/#comments</comments>
		<pubDate>Mon, 14 Jun 2010 13:57:24 +0000</pubDate>
		<dc:creator>mythworks</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[like]]></category>
		<category><![CDATA[like and not like]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[not like]]></category>
		<category><![CDATA[select]]></category>

		<guid isPermaLink="false">http://arimita.web.id/?p=224</guid>
		<description><![CDATA[The like and not like have two search symbols. The underscore _ character that looks for one character and the percentage % character that looks for zero or more characters. I use function  table which has function_name,  function_name and function_description fields. Lets see the example:

SELECT *
FROM `functions`
WHERE function_name LIKE 'a%'
LIMIT 0 , 30

Above query will [...]]]></description>
			<content:encoded><![CDATA[<p>The like and not like have two search symbols. The underscore _ character that looks for one character and the percentage % character that looks for zero or more characters. I use function  table which has function_name,  function_name and function_description fields. Lets see the example:</p>
<pre class="brush: sql;">
SELECT *
FROM `functions`
WHERE function_name LIKE 'a%'
LIMIT 0 , 30
</pre>
<p>Above query will only pick out result that provide a TRUE result according to the WHERE equation. We can see that equation will equal the LIKE value plus some possible extra characters afterwards.</p>
<p>The LIKE search is not case sensitive, so it will accept anything starting with ‘a’ as well.</p>
<p>So how LIKE search can make a different lowercase or uppercase letters? by adding BINARY word after LIKE.</p>
<pre class="brush: sql;">
SELECT *
FROM `functions`
WHERE function_name LIKE BINARY &quot;a%&quot;
LIMIT 0 , 30;
</pre>
<p>And the change the query like below to see the different:</p>
<pre class="brush: sql;">
SELECT *
FROM `functions`
WHERE function_name LIKE BINARY &quot;A%&quot;
LIMIT 0 , 30;
</pre>
<p>Queries using the LIKE or NOT LIKE parameters may be a bit slower than a normal query search considering they are a broader value and do not take advantage of any indexing.</p>
<p>Note: If you want to have an underscore or percentage character actually be part of the search value, put an escape slash \ in front of the character.</p>
<p>The underscore wildcard can be used a number of times to find a specific number of characters. Example, this would be used in an equation to return a value of &#8216;Stan&#8217; plus 3 characters.</p>
<pre class="brush: sql;">
SELECT *
FROM `functions`
WHERE function_name LIKE BINARY &quot;mdat___&quot;
LIMIT 0 , 30;
</pre>
<p>The underscore and percentage characters (also known as wildcard) can be used in front, at the end, or both ends of a value.</p>
]]></content:encoded>
			<wfw:commentRss>http://arimita.web.id/2010/06/like-and-not-like/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Operator Precedence</title>
		<link>http://arimita.web.id/2010/06/operator-precedence/</link>
		<comments>http://arimita.web.id/2010/06/operator-precedence/#comments</comments>
		<pubDate>Mon, 14 Jun 2010 13:41:53 +0000</pubDate>
		<dc:creator>mythworks</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[operator precedence]]></category>

		<guid isPermaLink="false">http://arimita.web.id/?p=218</guid>
		<description><![CDATA[The precedence of operators determines the order of evaluation. To override this order and group terms explicity, use parentheses. Lets see the example below:

Select 6+2-4*1, (6+2-4)*1;

Operator are shown bellow from lowest to the highest precedence. Operators shown together on a line have the same precedence. Lets take a look:
:=
&#124;&#124;, OR, XOR
&#38;&#38;, AND
NOT
BETWEEN, CASE, WHEN, THEN, [...]]]></description>
			<content:encoded><![CDATA[<p>The precedence of operators determines the order of evaluation. To override this order and group terms explicity, use parentheses. Lets see the example below:</p>
<pre class="brush: sql;">
Select 6+2-4*1, (6+2-4)*1;
</pre>
<p>Operator are shown bellow from lowest to the highest precedence. Operators shown together on a line have the same precedence. Lets take a look:</p>
<p>:=<br />
||, OR, XOR<br />
&amp;&amp;, AND<br />
NOT<br />
BETWEEN, CASE, WHEN, THEN, ELSE<br />
=, &lt;=&gt;, &gt;=, &gt;, &lt;=, &lt;, &lt;&gt;, !=, IS, LIKE, REGEXP, IN<br />
|<br />
&amp;<br />
&lt;&lt;, &gt;&gt;<br />
-, +<br />
*, /, DIV, %, MOD<br />
^<br />
- (unary minus), ~ (unary bit inversion)<br />
!<br />
BINARY, COLLATE</p>
<p>Note: If the HIGH_NOT_PRECEDENCE SQL mode is enabled, the precedence of NOT is the same as that of the ! operator.</p>
]]></content:encoded>
			<wfw:commentRss>http://arimita.web.id/2010/06/operator-precedence/feed/</wfw:commentRss>
		<slash:comments>70</slash:comments>
		</item>
	</channel>
</rss>

