Difference between revisions of "CALCULATED Column Constraint"

From Lianjapedia
Jump to: navigation, search
m (1 revision: SQL)
 
Line 1: Line 1:
 
==Purpose==
 
==Purpose==
 
Column constraint to calculate the value of a column
 
Column constraint to calculate the value of a column
 
  
 
==Syntax==
 
==Syntax==
 
CALCULATED <expr>  
 
CALCULATED <expr>  
 
  
 
==See Also==
 
==See Also==
 
[[ALTER TABLE]], [[SQL Constraints|CONSTRAINTS]], [[CREATE TABLE]]
 
[[ALTER TABLE]], [[SQL Constraints|CONSTRAINTS]], [[CREATE TABLE]]
 
  
 
==Description==
 
==Description==
Line 15: Line 12:
  
 
The CALCULATED column constraint is used to calculate the value of a column whenever it is accessed.  The <expr> specified must evaluate to the same data type as the target column.  Specifying the CALCULATED column constraint causes the column to be read only.  If the <expr> is based on other columns from the same table, these columns must have the RECALCULATE column constraint set, so that any changes to their values cause calculated fields to be recalculated.
 
The CALCULATED column constraint is used to calculate the value of a column whenever it is accessed.  The <expr> specified must evaluate to the same data type as the target column.  Specifying the CALCULATED column constraint causes the column to be read only.  If the <expr> is based on other columns from the same table, these columns must have the RECALCULATE column constraint set, so that any changes to their values cause calculated fields to be recalculated.
 
  
 
==Example==
 
==Example==
Line 26: Line 22:
  
  
==Products==
 
Recital, Recital Server
 
 
[[Category:Documentation]]
 
[[Category:Documentation]]
 
[[Category:SQL]]
 
[[Category:SQL]]

Latest revision as of 07:36, 7 December 2012

Purpose

Column constraint to calculate the value of a column

Syntax

CALCULATED <expr>

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 CALCULATED column constraint is used to calculate the value of a column whenever it is accessed. The <expr> specified must evaluate to the same data type as the target column. Specifying the CALCULATED column constraint causes the column to be read only. If the <expr> is based on other columns from the same table, these columns must have the RECALCULATE column constraint set, so that any changes to their values cause calculated fields to be recalculated.

Example

ALTER TABLE customer;
  ALTER COLUMN available CALCULATED limit-balance;
  ALTER COLUMN limit RECALCULATE;
  ALTER COLUMN balance RECALCULATE