Powered by SmartDoc

unique

The extention syntax unique specifies a UNIQUE constraint for a target column.

Target

A target of the unique is the property for the UNIQUE constraint.

Parameters

The unique attribute takes one of the following values as a parameter:

true
The UNIQUE constraint is available.
false
The UNIQUE constraint is not available.

Artifact

If true, UNIQUE constraint is specified for the target column in the DDL.

Example

List 13.4.4.1[unique.rng] is a sample schema for the unique attribute.

unique.rng
<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.

account.ddl
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)
)