Difference between revisions of "CHOICES Column Constraint"
From Lianjapedia
Yvonne.milne (Talk | contribs) (Created page with "==Purpose== Column constraint to specify a choice list for a character column ==Syntax== SET CHOICES <expC> ==See Also== ALTER TABLE, CONSTRAINTS, [[...") |
Yvonne.milne (Talk | contribs) |
||
(2 intermediate revisions by the same user not shown) | |||
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 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== | ||
<code lang="recital"> | <code lang="recital"> | ||
open database southwind | open database southwind | ||
+ | // Static choices | ||
ALTER TABLE "example" MODIFY CONSTRAINT TITLE SET CHOICES "Mr,Mrs,Ms" | 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" | ||
</code> | </code> | ||
[[Category:Documentation]] | [[Category:Documentation]] | ||
[[Category:SQL]] | [[Category:SQL]] |
Latest revision as of 11:17, 11 February 2013
Contents
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"