<?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>djsipe.com &#187; Pro Tips</title>
	<atom:link href="http://blog.djsipe.com/category/pro-tips/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.djsipe.com</link>
	<description>Web Development</description>
	<lastBuildDate>Sat, 31 Dec 2011 16:25:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Searching Your MySQL Schema (Yes, It&#8217;s Very Meta)</title>
		<link>http://blog.djsipe.com/2009/09/14/searching-your-mysql-schema-yes-its-very-meta/</link>
		<comments>http://blog.djsipe.com/2009/09/14/searching-your-mysql-schema-yes-its-very-meta/#comments</comments>
		<pubDate>Tue, 15 Sep 2009 01:07:35 +0000</pubDate>
		<dc:creator>DJ</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Pro Tips]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.djsipe.com/2009/09/14/searching-your-mysql-schema-yes-its-very-meta/</guid>
		<description><![CDATA[A common problem in complex database systems is an over-abundance of tables, columns, procedures, functions, and the databases that hold them.  Trying to figure out the right columns to use in that reporting query your boss wants by the end of the day can get just a little overwhelming.  Thankfully, there is an easy way [...]]]></description>
			<content:encoded><![CDATA[<p>A common problem in complex database systems is an over-abundance of tables, columns, procedures, functions, and the databases that hold them.  Trying to figure out the right columns to use in that reporting query your boss wants by the end of the day can get just a little overwhelming.  Thankfully, there is an easy way to drill down into the structure of your database so you can find just what you&#8217;re looking for.</p>
<p>Behold, your <a href="http://dev.mysql.com/doc/refman/5.0/en/information-schema.html" target="_blank">information_schema</a> database&#8230; The <em>information_schema</em> database is a special database that MySQL uses to keep track of its own internal plumbling.  It holds meta information on every field, column, table, and database on your MySQL server.  For this reason you <strong>must</strong> treat this database like royalty.  No inserting, updating, or deleting <em>anything</em> unless you want to have to rebuild all your tables.  That said, running selects is harmless enough and if you keep it to that you should be just fine.</p>
<h3>Searching For a Column</h3>
<p>Here&#8217;s a quick way to search for columns in any database by column name:</p>
<pre class="brush: sql; title: ; notranslate">
-- Search for column name containing &quot;bar&quot;
SELECT *
FROM information_schema.COLUMNS
WHERE
COLUMN_NAME LIKE '%bar%';
</pre>
<h3>Searching For a Table</h3>
<p>Need to narrow it down? Search by column name <em>and</em> table name.</p>
<pre class="brush: sql; title: ; notranslate">
-- Search only in tables beginning with &quot;foo&quot; for columns with &quot;bar&quot; in it
SELECT *
FROM information_schema.COLUMNS
WHERE
COLUMN_NAME LIKE '%bar%' AND
TABLE_NAME LIKE 'foo%';
</pre>
<h3>Find Columns Used in Stored Procedures or Triggers</h3>
<p>Being able to quickly track down all the places a given column can be updated in your database is extremely useful when it comes time to hunt down an illusive bug. Here&#8217;s how you can quickly narrow your search to only the stored procedures, functions, and triggers that actually mention your column somewhere in their code:</p>
<pre class="brush: sql; title: ; notranslate">

-- Search all stored procedures and functions for &quot;foobar_column&quot;
SELECT *
FROM information_schema.ROUTINES
WHERE
ROUTINE_DEFINITION LIKE '%foobar_column%';

-- Search all triggers for &quot;foobar_column&quot;
SELECT *
FROM information_schema.TRIGGERS
WHERE
ACTION_STATEMENT LIKE '%foobar_column%';
</pre>
<p>There&#8217;s a whole bunch of other tables to play with in the <em>information_schema</em> table, so dig in&#8230; but remember look, don&#8217;t touch.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.djsipe.com/2009/09/14/searching-your-mysql-schema-yes-its-very-meta/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

