<?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>emson... &#187; sql</title>
	<atom:link href="http://blog.emson.co.uk/category/sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.emson.co.uk</link>
	<description></description>
	<lastBuildDate>Thu, 24 Jun 2010 08:27:48 +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>Everyday MySQL Commands</title>
		<link>http://blog.emson.co.uk/2008/08/everyday-mysql-commands/</link>
		<comments>http://blog.emson.co.uk/2008/08/everyday-mysql-commands/#comments</comments>
		<pubDate>Tue, 19 Aug 2008 00:45:51 +0000</pubDate>
		<dc:creator>ben</dc:creator>
				<category><![CDATA[databases]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://blog.emson.co.uk/2008/08/everyday-mysql-commands/</guid>
		<description><![CDATA[I&#8217;m trying to put together a number of blog articles and many of them use the MySQL database, so I figured that I would post up some of my most used everyday MySQL SQL commands.  Most likely I will append further commands as I write more articles so this is page is really a [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m trying to put together a number of blog articles and many of them use the MySQL database, so I figured that I would post up some of my most used everyday MySQL SQL commands.  Most likely I will append further commands as I write more articles so this is page is really a work in progress.</p>

<p>I&#8217;ve also assumed that you want to have full rights when executing these commands so I&#8217;ve used <strong>sudo</strong>, however you may not need this depending on your set up.</p>

<p>Finally if some other web site covers the command better or I&#8217;m feeling lazy I&#8217;ll just pop it in the links list at the bottom of this page.</p>

<h2>Useful MySQL Commands</h2>

<h3>Starting MySQL Demon</h3>

<p>Start your MySQL database and get it running as a background process:</p>

<pre><code>sudo mysqld_safe
Ctrl + Z
bg
</code></pre>

<h3>MySQL create databases script</h3>

<p>Make a SQL script that creates 3 databases and assigns all rights to my username.
Copy the following SQL and paste it into a file called <strong>create_databases.sql</strong>:</p>

<pre><code>create database mydb_development;
create database mydb_test;
create database mydb_production;
grant all on mydb_development.* to 'my_username'@'localhost';
grant all on mydb_test.* to 'my_username'@'localhost';
grant all on mydb_production.* to 'my_username'@'localhost' identified by 'my_password';
</code></pre>

<h3>MySQL drop databases script</h3>

<p>Make a script to drop databases.
Copy the following SQL and paste it into a file called <strong>drop_databases.sql</strong>:</p>

<pre><code>drop database nemos_production;
drop database mydb_development;
drop database nemos_test;
</code></pre>

<h3>Executing a script from MySQL</h3>

<p>The above scripts can be executed from the command-line with the either of these commands:</p>

<pre><code>sudo mysql &lt; create_database.sql
or
sudo mysql &lt; drop_database.sql
</code></pre>

<h3>Showing MySQL databases</h3>

<p>To check that the databases were created :</p>

<pre><code>sudo mysqlshow
or
sudo mysql
show databases;
</code></pre>

<h3>Displaying database tables</h3>

<p>Displaying the tables of a database:</p>

<pre><code>sudo mysqlshow mydb_development
or
sudo mysql
show tables from mydb_development;
</code></pre>

<h3>Displaying details about a database table</h3>

<p>Displaying details about a particular database table:</p>

<pre><code>sudo mysqlshow mydb_development mytable
</code></pre>

<h3>Droping a database table</h3>

<p>Dropping a table from a database:</p>

<pre><code>sudo mysql
use mydb_development;
drop table mytable;
</code></pre>

<h3>Displaying information about a table</h3>

<p>Displaying the fields and field metadata about a table:</p>

<pre><code>show fields from my_table; 
or
desc my_table;
</code></pre>

<h2>Useful Links</h2>

<ul>
<li><a href="http://openmaniak.com/mysql.php">http://openmaniak.com/mysql.php</a></li>
</ul>

<p>These are just a few quick and simple MySQL commands that you will always use.
Hope this helps.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.emson.co.uk/2008/08/everyday-mysql-commands/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to determine whether a column exists on SQLServer</title>
		<link>http://blog.emson.co.uk/2008/06/how-to-determine-whether-a-column-exists-on-sqlserver/</link>
		<comments>http://blog.emson.co.uk/2008/06/how-to-determine-whether-a-column-exists-on-sqlserver/#comments</comments>
		<pubDate>Tue, 10 Jun 2008 15:14:42 +0000</pubDate>
		<dc:creator>ben</dc:creator>
				<category><![CDATA[sql]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://blog.emson.co.uk/2008/06/how-to-determine-whether-a-column-exists-on-sqlserver/</guid>
		<description><![CDATA[I run some SQL scripts against Microsoft&#8217;s SQLServer in a number of environments, test, staging and production.

One of my problems is that these scripts alter the database schema and I only want them to execute if the change hasn&#8217;t already been made.

One of these changes was to remove a column from the database, so my [...]]]></description>
			<content:encoded><![CDATA[<p>I run some SQL scripts against Microsoft&#8217;s SQLServer in a number of environments, test, staging and production.</p>

<p>One of my problems is that these scripts alter the database schema and I only want them to execute if the change hasn&#8217;t already been made.</p>

<p>One of these changes was to remove a column from the database, so my question is &#8216;how can I ask SQLServer whether a particular column exists&#8217;.</p>

<p>Well the SQL query to check if a column exists and execute a query if it does is as follows:</p>

<pre><code>IF EXISTS ( SELECT * FROM INFORMATION_SCHEMA.COLUMNS
                 WHERE TABLE_NAME='my_table_name' AND
                 COLUMN_NAME='my_column_name' )
BEGIN
  PRINT 'Execute some query here'
END
</code></pre>

<p>Hope it is useful.
Ben&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.emson.co.uk/2008/06/how-to-determine-whether-a-column-exists-on-sqlserver/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
