Difference between revisions of "CHECK Column Constraint"

From Recital Documentation Wiki
Jump to: navigation, search
 
(2 intermediate revisions by one user not shown)
Line 19: Line 19:
 
==Example==
 
==Example==
 
<code lang="recital">
 
<code lang="recital">
set sql to recital
+
ALTER TABLE customer;
exec sql
+
  ADD COLUMN timeref CHAR(8);
ALTER TABLE customer ADD COLUMN timeref char(8) CHECK validtime(timeref)
+
  CHECK validtime(timeref);
ERROR "Not a valid time string";
+
  ERROR "Not a valid time string"
use customer
+
edit
+
 
</code>
 
</code>
  
  
 
==Products==
 
==Products==
Recital Database Server, Recital Mirage Server, Recital Terminal Developer
+
Recital, Recital Server
 
[[Category:Documentation]]
 
[[Category:Documentation]]
 
[[Category:SQL]]
 
[[Category:SQL]]

Latest revision as of 11:19, 22 December 2009

Purpose

Column constraint to validate a change to the value of a column


Syntax

CHECK <condition>


See Also

ALTER TABLE, CONSTRAINTS, CREATE TABLE


Description

A constraint is used to define rules that help to provide data integrity. Column constraints are specific to the column name specified. You must have ALTER privilege on the table. The table will be locked for EXCLUSIVE use during the operation.

The CHECK column constraint is used to validate any changes made to the value of a column. The <condition> specified must evaluate to True (.T.) for the modification operation to succeed. If the <condition> evaluates to False (.F.) the column value remains unchanged and the ERROR column constraint message is displayed. If the ERROR column constraint has not been defined, a default error message is displayed.


Example

ALTER TABLE customer;
  ADD COLUMN timeref CHAR(8);
  CHECK validtime(timeref);
  ERROR "Not a valid time string"


Products

Recital, Recital Server