<?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; SQL</title>
	<atom:link href="http://jordanhall.co.uk/tag/sql/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 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>

