Difference between revisions of "REFERENCES Column Constraint"

From Lianjapedia
Jump to: navigation, search
m (1 revision: SQL)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
==Purpose==
 
==Purpose==
 
Column constraint to create a relationship to an index key of another table
 
Column constraint to create a relationship to an index key of another table
 
  
 
==Syntax==
 
==Syntax==
REFERENCES <cTableName> [TAG <cTagName>]
+
REFERENCES <cTableName> TAG <cTagName>
 
+
  
 
==See Also==
 
==See Also==
 
[[ALTER TABLE]], [[SQL Constraints|CONSTRAINTS]], [[CREATE TABLE]]
 
[[ALTER TABLE]], [[SQL Constraints|CONSTRAINTS]], [[CREATE TABLE]]
 
  
 
==Description==
 
==Description==
Line 16: Line 13:
 
The REFERENCES column constraint is used to create a relationship to an index key of another table.  The value of a column which has the REFERENCES column constraint set is validated by checking that it already exists as a value in the referenced index key.
 
The REFERENCES column constraint is used to create a relationship to an index key of another table.  The value of a column which has the REFERENCES column constraint set is validated by checking that it already exists as a value in the referenced index key.
  
The name of the referenced table is specified in <cTableName>.  The index tag to reference is specified in <cTagName>. If the optional TAG <cTagName> clause is omitted, the primary index key of <cTableName> is used.  If <cTableName> has no index tags, an error is generated.
+
The name of the referenced table is specified in <cTableName>.  The index tag to reference is specified in <cTagName>.
 
+
  
 
==Example==
 
==Example==
Line 29: Line 25:
 
   POtotal n(10,2))
 
   POtotal n(10,2))
 
</code>
 
</code>
 
  
 
==Products==
 
==Products==
Recital, Recital Server
+
Lianja, Lianja Server
 
[[Category:Documentation]]
 
[[Category:Documentation]]
 
[[Category:SQL]]
 
[[Category:SQL]]

Latest revision as of 10:58, 29 January 2016

Purpose

Column constraint to create a relationship to an index key of another table

Syntax

REFERENCES <cTableName> TAG <cTagName>

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 REFERENCES column constraint is used to create a relationship to an index key of another table. The value of a column which has the REFERENCES column constraint set is validated by checking that it already exists as a value in the referenced index key.

The name of the referenced table is specified in <cTableName>. The index tag to reference is specified in <cTagName>.

Example

CREATE TABLE supplier;
  (SuppId i PRIMARY KEY,;
  SuppName c(40) UNIQUE)
CREATE TABLE purchase_order;
  (POid i PRIMARY KEY,;
  SuppId i REFERENCES supplier TAG SuppId,;
  POtotal n(10,2))

Products

Lianja, Lianja Server