The extention syntax unique
specifies a UNIQUE constraint
for a target column.
A target of the unique is the property for the UNIQUE constraint.
The unique attribute takes one of the following values as a parameter:
If true
, UNIQUE constraint is specified for the target column in the DDL.
List 13.4.4.1[unique.rng] is a sample schema for the unique attribute.
<grammar xmlns="http://relaxng.org/ns/structure/1.0" xmlns:sql="http://www.relaxer.org/xmlns/relaxer/sql" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"> <start> <ref name="account"/> </start> <define name="account"> <element name="account"> <attribute name="accountNo" sql:unique="true"> <data type="token"/> </attribute> <element name="balance"> <data type="int"/> </element> <element name="owner"> <data type="token"/> </element> <ref name="address"/> <zeroOrMore> <ref name="phone"/> </zeroOrMore> </element> </define> <define name="address"> <element name="address"> <attribute name="zip"> <data type="token"/> </attribute> <text/> </element> </define> <define name="phone"> <element name="phone"> <attribute name="area"> <data type="token"/> </attribute> <data type="token"/> </element> </define> </grammar>
In the schema, the extension attribute sql:unique
is specified
in the element named accountNo
.
This definition means that this column will have a UNIQUE constraint.
Execution of Relaxer with the unique attribute is as follows. No special options are required.
$ relaxer -jdbc unique.rng
As a result, Relaxer generates 13 files:
The file account.ddl shown in List 13.4.4.2[account.ddl]
shows the effect of the unique attribute:
A column accountNo
has a UNIQUE constraint.
CREATE TABLE "account" ( "accountNo" VARCHAR(32) UNIQUE, "balance" INTEGER NOT NULL, "owner" VARCHAR(32) NOT NULL, "address" VARCHAR(128) NOT NULL, "address_zip" VARCHAR(32) NOT NULL, "phone" VARCHAR(512) )