Difference between revisions of "CHOICES Column Constraint"

From Lianjapedia
Jump to: navigation, search
 
Line 11: Line 11:
 
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.
 
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 CHOICES column constraint is used to specify a choice list for a character column.  The <expC> can be a static choice list based on comma-separated options or a dynamic choice list using "@tablename,expression" or a Lianja [[SQL Select]] statement.
+
The CHOICES column constraint is used to specify a choice list for a character column.  The <expC> can be a static choice list based on comma-separated options or a dynamic choice list using "@tablename,expression" or a [[SQL SELECT]] statement.
  
 
==Example==
 
==Example==

Latest revision as of 11:17, 11 February 2013

Purpose

Column constraint to specify a choice list for a character column

Syntax

SET CHOICES <expC>

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 CHOICES column constraint is used to specify a choice list for a character column. The <expC> can be a static choice list based on comma-separated options or a dynamic choice list using "@tablename,expression" or a SQL SELECT statement.

Example

open database southwind
// Static choices
ALTER TABLE "example" MODIFY CONSTRAINT TITLE SET CHOICES "Mr,Mrs,Ms"
// Dynamic choices @tablename,expression
ALTER TABLE "orders" MODIFY CONSTRAINT CUSTOMERID SET CHOICES "@customers,customerid"
// Dynamic choices SQL Select
ALTER TABLE "orders" MODIFY CONSTRAINT CUSTOMERID SET CHOICES "select customerid from customers"