Powered by SmartDoc

notNull

The extention syntax notNull specifies a NOT NULL constraint for a target column.

Target

A target of the notNull is the property for the NOT NULL constraint.

Parameters

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

true
The NOT NULL constraint is available.
false
The NOT NULL constraint is not available.

Artifact

If true, NOT NULL constraint is specified at the target column in a DDL.

Example

List 13.5.4.1[notNull.rng] is a sample schema for the notNull attribute.

notNull.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:notNull="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" sql:notNull="false">
        <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:notNull is specified in the element named accountNo. This definition means that the this column will have a NOT NULL constraint.

Execution of Relaxer with the notNull attribute is as follows. No special options are required.

$ relaxer -jdbc notNull.rng

As a result, Relaxer generates 13 files:

The file account.ddl, in List 13.5.4.2[account.ddl], shows the effect of the notNull attribute. A column accountNo has a NOT NULL constraint.

account.ddl
CREATE TABLE "account" (
	"accountNo" VARCHAR(32) NOT NULL,
	"balance" INTEGER NOT NULL,
	"owner" VARCHAR(32) NOT NULL,
	"address" VARCHAR(128) NOT NULL,
	"address_zip" VARCHAR(32),
	"phone" VARCHAR(512)
)