<?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>Jordan Hall &#187; check constraints</title>
	<atom:link href="http://jordanhall.co.uk/tag/check-constraints/feed/" rel="self" type="application/rss+xml" />
	<link>http://jordanhall.co.uk</link>
	<description>Jordan Hall - programmer and geek</description>
	<lastBuildDate>Thu, 19 Jan 2012 11:36:06 +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>SQL Check Constraints not supported in MySQL</title>
		<link>http://jordanhall.co.uk/general-articles/sql-check-constraints-not-supported-in-mysql-2204849/</link>
		<comments>http://jordanhall.co.uk/general-articles/sql-check-constraints-not-supported-in-mysql-2204849/#comments</comments>
		<pubDate>Sat, 10 Apr 2010 16:12:22 +0000</pubDate>
		<dc:creator>Jordan Hall</dc:creator>
				<category><![CDATA[General Articles]]></category>
		<category><![CDATA[check constraints]]></category>
		<category><![CDATA[constraints]]></category>
		<category><![CDATA[database schema]]></category>
		<category><![CDATA[database validation]]></category>
		<category><![CDATA[databases]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[validation]]></category>

		<guid isPermaLink="false">http://jordanhall.co.uk/?p=849</guid>
		<description><![CDATA[I previously wrote about using SQL check constraints in MySQL. It seems however that the MySQL relational database management system (RDBMS) does not actually support the fundamental verification used by check constraints in other RDBMSs. This means that although you can add check constraints to tables without issue, they are not validated and data is [...]]]></description>
			<content:encoded><![CDATA[<p>I previously wrote about using <a href="http://jordanhall.co.uk/general-articles/sql-check-constraints-on-mysql-databases-2102526/">SQL check constraints in MySQL</a>. It seems however that the MySQL relational database management system (RDBMS) does not actually support the fundamental verification used by check constraints in other RDBMSs. This means that although you can add check constraints to tables without issue, they are not validated and data is inserted or updated.</p>
<p>The latest <a href="http://dev.mysql.com/doc/refman/5.5/en/table-constraints-table.html">MySQL documentation</a> (5.5) discretly mentions the fact these constraints are unfortunately not supported.</p>
<blockquote>
<ul>
<li>The CONSTRAINT_TYPE value can be UNIQUE, PRIMARY KEY, or FOREIGN KEY.</li>
<li>The UNIQUE and PRIMARY KEY information is about the same as what you get from the Key_name field in the output from SHOW INDEX when the Non_unique field is 0.</li>
<li>The CONSTRAINT_TYPE column can contain one of these values: UNIQUE, PRIMARY KEY, FOREIGN KEY, CHECK. This is a CHAR (not ENUM) column. <strong>The CHECK value is not available until we support CHECK.</strong></li>
</ul>
</blockquote>
<p>Take special note of the final line I&#8217;ve emboldened. This is quite a shame that this constraint type is not fully supported yet.</p>
<p>Apologies to readers for the implication that this was functional in my previous post, and thanks to the poster of <a href="http://jordanhall.co.uk/general-articles/sql-check-constraints-on-mysql-databases-2102526/comment-page-1/#comment-1370">this comment</a> for noticing the discrepancy.</p>
<p>Check constraints, of course, function fine in many other DBMSs, and to that end, the original post on <a href="http://jordanhall.co.uk/general-articles/sql-check-constraints-on-mysql-databases-2102526/">SQL check constraints</a> is still relevant, but sadly not if you are worked with MySQL.</p>
]]></content:encoded>
			<wfw:commentRss>http://jordanhall.co.uk/general-articles/sql-check-constraints-not-supported-in-mysql-2204849/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>SQL Check Constraints on MySQL Databases</title>
		<link>http://jordanhall.co.uk/general-articles/sql-check-constraints-on-mysql-databases-2102526/</link>
		<comments>http://jordanhall.co.uk/general-articles/sql-check-constraints-on-mysql-databases-2102526/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 13:25:21 +0000</pubDate>
		<dc:creator>Jordan Hall</dc:creator>
				<category><![CDATA[General Articles]]></category>
		<category><![CDATA[check constraints]]></category>
		<category><![CDATA[database schema]]></category>
		<category><![CDATA[database validation]]></category>
		<category><![CDATA[databases]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Check Constraints]]></category>

		<guid isPermaLink="false">http://jordanhall.co.uk/?p=526</guid>
		<description><![CDATA[An SQL check constraint is used and designed in the schema of a database table to restrict the range of values that can be entered into a specific field. In many experienced, they are very rarely used. However, these simple checks, entered at the time of database table creation, can provide additional safe guards against [...]]]></description>
			<content:encoded><![CDATA[<p>An SQL check constraint is used and designed in the schema of a database table to restrict the range of values that can be entered into a specific field. In many experienced, they are very rarely used. However, these simple checks, entered at the time of database table creation, can provide additional safe guards against &#8216;bad&#8217; data getting into your database tables, either via errors in code or simply user area. SQL check constraints can act as a last line of defence against &#8216;bad&#8217; data, as it is verification at the database level.</p>
<p>You can create a table with a check constraint in MySQL as follows. The check in this example disallows values of the &#8216;P_Id&#8217; field from falling outside of the condition &#8216;P_Id&gt;0&#8242;. In other words, the &#8216;P_Id&#8217; field&#8217;s values must almost be greater than zero in order for the data to be accepted into the table by the database management system (DBMS).</p>
<pre>CREATE TABLE Persons
(
P_Id int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255),
CHECK (P_Id&gt;0)
)</pre>
<p>You are probably wondering how to add a constraint to an existing database table. This is quite easy, and uses an &#8216;ALTER TABLE&#8217; SQL query. See the following example for how to add a check constraint to one of your existing database tables.</p>
<pre>ALTER TABLE Persons
ADD CHECK (P_Id&gt;0)</pre>
<p>For more information, there are other highly useful example queries relating to SQL check constraints at the relevant <a href="http://www.w3schools.com/Sql/sql_check.asp">SQL check constraint article</a> on <a href="http://www.w3schools.com/">W3schools</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://jordanhall.co.uk/general-articles/sql-check-constraints-on-mysql-databases-2102526/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

