<?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>Geekality &#187; SQL</title>
	<atom:link href="http://www.geekality.net/tag/sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.geekality.net</link>
	<description>With a hint of Social Ineptitude</description>
	<lastBuildDate>Sun, 05 Feb 2012 17:53:50 +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>Oracle: Finding all constraints and their affected columns</title>
		<link>http://www.geekality.net/2012/01/12/oracle-finding-all-constraints-and-their-affected-columns/</link>
		<comments>http://www.geekality.net/2012/01/12/oracle-finding-all-constraints-and-their-affected-columns/#comments</comments>
		<pubDate>Thu, 12 Jan 2012 17:18:28 +0000</pubDate>
		<dc:creator>Torleif</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Foreign Keys]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[RDMS]]></category>
		<category><![CDATA[Search]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.geekality.net/?p=1899</guid>
		<description><![CDATA[Found an SQL script to list all constraints in an Oracle database together with affected columns. Putting it here in case I need it again&#8230; Took a while to run, but sure beats having to look through all the table &#8230; <a href="http://www.geekality.net/2012/01/12/oracle-finding-all-constraints-and-their-affected-columns/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Found <a href="http://blog.mclaughlinsoftware.com/2009/03/05/validating-foreign-keys/">an SQL script</a> to list all constraints in an Oracle database together with affected columns. Putting it here in case I need it again&#8230; Took a while to run, but sure beats having to look through all the table definitions to find what exactly is preventing me from deleting a row&#8230;</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">SELECT</span> UC<span style="color: #66cc66;">.</span>OWNER<br />
<span style="color: #66cc66;">,</span> &nbsp; &nbsp; &nbsp;UC<span style="color: #66cc66;">.</span>CONSTRAINT_NAME<br />
<span style="color: #66cc66;">,</span> &nbsp; &nbsp; &nbsp;UCC1<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">TABLE_NAME</span><span style="color: #66cc66;">||</span><span style="color: #ff0000;">'.'</span><span style="color: #66cc66;">||</span>UCC1<span style="color: #66cc66;">.</span>COLUMN_NAME <span style="color: #ff0000;">&quot;CONSTRAINT_SOURCE&quot;</span><br />
<span style="color: #66cc66;">,</span> &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">'REFERENCES'</span><br />
<span style="color: #66cc66;">,</span> &nbsp; &nbsp; &nbsp;UCC2<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">TABLE_NAME</span><span style="color: #66cc66;">||</span><span style="color: #ff0000;">'.'</span><span style="color: #66cc66;">||</span>UCC2<span style="color: #66cc66;">.</span>COLUMN_NAME <span style="color: #ff0000;">&quot;REFERENCES_COLUMN&quot;</span><br />
<span style="color: #993333; font-weight: bold;">FROM</span> USER_CONSTRAINTS uc<br />
<span style="color: #66cc66;">,</span> &nbsp; &nbsp;USER_CONS_COLUMNS ucc1<br />
<span style="color: #66cc66;">,</span> &nbsp; &nbsp;USER_CONS_COLUMNS ucc2<br />
<span style="color: #993333; font-weight: bold;">WHERE</span> UC<span style="color: #66cc66;">.</span>CONSTRAINT_NAME <span style="color: #66cc66;">=</span> UCC1<span style="color: #66cc66;">.</span>CONSTRAINT_NAME<br />
&nbsp; <span style="color: #993333; font-weight: bold;">AND</span> UC<span style="color: #66cc66;">.</span>R_CONSTRAINT_NAME <span style="color: #66cc66;">=</span> UCC2<span style="color: #66cc66;">.</span>CONSTRAINT_NAME<br />
&nbsp; <span style="color: #993333; font-weight: bold;">AND</span> UCC1<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">POSITION</span> <span style="color: #66cc66;">=</span> UCC2<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">POSITION</span> <span style="color: #808080; font-style: italic;">-- Correction for multiple column primary keys.</span><br />
&nbsp; <span style="color: #993333; font-weight: bold;">AND</span> UC<span style="color: #66cc66;">.</span>CONSTRAINT_TYPE <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'R'</span><br />
<span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> UCC1<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">TABLE_NAME</span><br />
<span style="color: #66cc66;">,</span> &nbsp; &nbsp; &nbsp; &nbsp;UC<span style="color: #66cc66;">.</span>CONSTRAINT_NAME;</div></div>
<p>If you&#8217;re just looking for one particular constraint you can of course also add <code class="codecolorer text default"><span class="text">and UC.CONSTRAINT_NAME = 'SOME NAME'</span></code> <img src='http://www.geekality.net/wp-includes/images/blank.gif' alt=':)' class='wp-smiley smiley-1' /> </p>
<p class="wp-flattr-button"></p> <p><a href="http://www.geekality.net/?flattrss_redirect&amp;id=1899&amp;md5=1e54a40d978718429a8c0f0fd8bba21f" title="Flattr" target="_blank"><img src="http://www.geekality.net/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.geekality.net/2012/01/12/oracle-finding-all-constraints-and-their-affected-columns/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL for listing all WordPress tags</title>
		<link>http://www.geekality.net/2011/06/13/sql-for-listing-all-wordpress-tags/</link>
		<comments>http://www.geekality.net/2011/06/13/sql-for-listing-all-wordpress-tags/#comments</comments>
		<pubDate>Mon, 13 Jun 2011 20:47:17 +0000</pubDate>
		<dc:creator>Torleif</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Blogging]]></category>
		<category><![CDATA[Snippet]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.geekality.net/?p=1715</guid>
		<description><![CDATA[When writing a post I sometimes find it difficult to choose what I should tag it with. I try reuse tags I already have to prevent a total mess, and sometimes I just don&#8217;t really remember what tags I have &#8230; <a href="http://www.geekality.net/2011/06/13/sql-for-listing-all-wordpress-tags/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>When writing a post I sometimes find it difficult to choose what I should tag it with. I try reuse tags I already have to prevent a total mess, and sometimes I just don&#8217;t really remember what tags I have used so far. When writing a post in WordPress you can get a list of the most used ones, but once in a while I write a post on subject I haven&#8217;t written a lot about. So, instead of going to the Post Tags page and look through all the pages of tags, I decided to just connect to my blog database and run a query.</p>
<p><span id="more-1715"></span></p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">SELECT</span> name<span style="color: #66cc66;">,</span> slug<span style="color: #66cc66;">,</span> description<span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">COUNT</span> <span style="color: #993333; font-weight: bold;">FROM</span> wp_terms<br />
<span style="color: #993333; font-weight: bold;">NATURAL</span> <span style="color: #993333; font-weight: bold;">JOIN</span> wp_term_taxonomy<br />
<span style="color: #993333; font-weight: bold;">WHERE</span> taxonomy<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;post_tag&quot;</span><br />
<span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> name</div></div>
<p>Lists all your tags, sorted by name <img src='http://www.geekality.net/wp-includes/images/blank.gif' alt=':)' class='wp-smiley smiley-1' /> </p>
<p class="wp-flattr-button"></p> <p><a href="http://www.geekality.net/?flattrss_redirect&amp;id=1715&amp;md5=9996d29443248765a13d414f1e0aa91c" title="Flattr" target="_blank"><img src="http://www.geekality.net/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.geekality.net/2011/06/13/sql-for-listing-all-wordpress-tags/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Oracle: How to search for a table or column in a big database</title>
		<link>http://www.geekality.net/2011/03/25/oracle-how-to-search-for-a-table-or-column-in-a-big-database/</link>
		<comments>http://www.geekality.net/2011/03/25/oracle-how-to-search-for-a-table-or-column-in-a-big-database/#comments</comments>
		<pubDate>Fri, 25 Mar 2011 07:54:43 +0000</pubDate>
		<dc:creator>Torleif</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Snippet]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.geekality.net/?p=1530</guid>
		<description><![CDATA[I needed to find columns containing a certain string. That is, the name of the column should contain that string. Actually not too difficult to do SELECT TABLE_NAME, column_name FROM all_tab_columns WHERE column_name LIKE '%FOO_ID%'; That gives you a nice &#8230; <a href="http://www.geekality.net/2011/03/25/oracle-how-to-search-for-a-table-or-column-in-a-big-database/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I needed to find columns containing a certain string. That is, the name of the column should contain that string. Actually not too difficult to do <img src='http://www.geekality.net/wp-includes/images/blank.gif' alt=':)' class='wp-smiley smiley-1' /> </p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">TABLE_NAME</span><span style="color: #66cc66;">,</span> column_name<br />
<span style="color: #993333; font-weight: bold;">FROM</span> all_tab_columns<br />
<span style="color: #993333; font-weight: bold;">WHERE</span> column_name <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'%FOO_ID%'</span>;</div></div>
<p>That gives you a nice list of all columns containing <code class="codecolorer text default"><span class="text">FOO_ID</span></code> and what tables you find them in. Fantastic! Now, back to work&#8230;</p>
<p class="wp-flattr-button"></p> <p><a href="http://www.geekality.net/?flattrss_redirect&amp;id=1530&amp;md5=ed10c79ee94f535d68b7d771d49c96fa" title="Flattr" target="_blank"><img src="http://www.geekality.net/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.geekality.net/2011/03/25/oracle-how-to-search-for-a-table-or-column-in-a-big-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL: How to clone a table</title>
		<link>http://www.geekality.net/2011/03/04/mysql-how-to-clone-a-table/</link>
		<comments>http://www.geekality.net/2011/03/04/mysql-how-to-clone-a-table/#comments</comments>
		<pubDate>Fri, 04 Mar 2011 17:51:36 +0000</pubDate>
		<dc:creator>Torleif</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Snippet]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.geekality.net/?p=1516</guid>
		<description><![CDATA[Ever wanted to, for some reason, clone a database table? Don&#8217;t really want to export anything or figure out what statement was used to create that table? Turns out that&#8217;s a lot easier to do than I thought it was. &#8230; <a href="http://www.geekality.net/2011/03/04/mysql-how-to-clone-a-table/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Ever wanted to, for some reason, clone a database table? Don&#8217;t really want to export anything or figure out what statement was used to create that table? Turns out that&#8217;s a lot easier to do than I thought it was.</p>
<p><span id="more-1516"></span></p>
<p>Stumbled over a blog post on how you can <a href="http://www.mehtanirav.com/2007/10/11/copying-a-mysql-table-with-schema-and-keys-but-not-data">copy a MySQL table with schema and keys</a>, and boy was it easy.</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> newtable <span style="color: #993333; font-weight: bold;">LIKE</span> oldtable;</div></div>
<p>And that&#8217;s it! Want the data copied over as well?</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> newtable <span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> oldtable;</div></div>
<p>Super easy! <img src='http://www.geekality.net/wp-includes/images/blank.gif' alt=':D' class='wp-smiley smiley-8' /> </p>
<p class="wp-flattr-button"></p> <p><a href="http://www.geekality.net/?flattrss_redirect&amp;id=1516&amp;md5=9ef9734d7f6fc8b3e50cb7fae9c3fed9" title="Flattr" target="_blank"><img src="http://www.geekality.net/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.geekality.net/2011/03/04/mysql-how-to-clone-a-table/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to delete WordPress post revisions</title>
		<link>http://www.geekality.net/2009/10/20/how-to-delete-wordpress-post-revisions/</link>
		<comments>http://www.geekality.net/2009/10/20/how-to-delete-wordpress-post-revisions/#comments</comments>
		<pubDate>Tue, 20 Oct 2009 21:40:23 +0000</pubDate>
		<dc:creator>Torleif</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.geekality.net/?p=689</guid>
		<description><![CDATA[Having revisions on my posts is nice I suppose. But I was starting to get a bit annoyed with the increasingly long list of revisions in each post. And they really did get long. Mainly because I am in a &#8230; <a href="http://www.geekality.net/2009/10/20/how-to-delete-wordpress-post-revisions/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Having revisions on my posts is nice I suppose. But I was starting to get a bit annoyed with the increasingly long list of revisions in each post. And they really did get long. Mainly because I am in a bit of a testing and experimenting phase which means that I have done a lot of adjustments to almost every single post so far because I don&#8217;t have 100% control on how I want things or how things will end up looking and so on <img src='http://www.geekality.net/wp-includes/images/blank.gif' alt=':P' class='wp-smiley smiley-13' /> There&#8217;s also of course all the obligatory spelling errors I only discover <em>after</em> I have clicked Publish <img src='http://www.geekality.net/wp-includes/images/blank.gif' alt=':P' class='wp-smiley smiley-13' /> </p>
<p>Anyways, I found a nice little MySQL snippet to clear out all of them in a French comment to <a href="http://www.mydigitallife.info/2008/07/22/how-to-delete-existing-wordpress-post-revisions-storedsaved/">a blog post</a>. Thought I could share it here. That way I won&#8217;t lose it either <img src='http://www.geekality.net/wp-includes/images/blank.gif' alt=':)' class='wp-smiley smiley-1' /> </p>
<p><span id="more-689"></span></p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">DELETE</span> x<span style="color: #66cc66;">,</span>y<span style="color: #66cc66;">,</span>z<br />
<span style="color: #993333; font-weight: bold;">FROM</span> wp_posts x<br />
<span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">JOIN</span> wp_term_relationships y <span style="color: #993333; font-weight: bold;">ON</span> <span style="color: #66cc66;">&#40;</span>x<span style="color: #66cc66;">.</span>id <span style="color: #66cc66;">=</span> y<span style="color: #66cc66;">.</span>object_id<span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">JOIN</span> wp_postmeta z <span style="color: #993333; font-weight: bold;">ON</span> <span style="color: #66cc66;">&#40;</span>x<span style="color: #66cc66;">.</span>id <span style="color: #66cc66;">=</span> z<span style="color: #66cc66;">.</span>post_id<span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">WHERE</span> x<span style="color: #66cc66;">.</span>post_type <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'revision'</span></div></div>
<p>You can swap <code class="codecolorer text default"><span class="text">delete x,y,z</span></code> with <code class="codecolorer text default"><span class="text">select *</span></code> to check that it will delete what you really want to.</p>
<p>Remember that if you have a table prefix other than &#8216;wp_&#8217; set in your wp-config.php, you need to change that in your SQL script before you run it. The line looks like this in my config file:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$table_prefix</span> &nbsp;<span style="color: #339933;">=</span> <span style="color: #0000ff;">'wp_'</span><span style="color: #339933;">;</span></div></div>
<p>I can also recommend setting WP_POST_REVISIONS to something in your wp-config.php file. Just search for REVISIONS in that file. If you don&#8217;t find it, you can just add it somewhere. The line should look like the following, where N would be how many revisions you want to allow, or -1 if you want them all:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WP_POST_REVISIONS'</span><span style="color: #339933;">,</span> N<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>I will still run the SQL script once in a while though, cause after a while my posts become sort of stable, and having revisions with my spelling errors hanging around for ever doesn&#8217;t really make sense in my head <img src='http://www.geekality.net/wp-includes/images/blank.gif' alt=':P' class='wp-smiley smiley-13' /> </p>
<p class="wp-flattr-button"></p>]]></content:encoded>
			<wfw:commentRss>http://www.geekality.net/2009/10/20/how-to-delete-wordpress-post-revisions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

