Object Types

This section describes the DDL commands pertaining to object types.

Define a new object type.

[ WITH with-item [, ...] ]
CREATE [ABSTRACT] TYPE name [ EXTENDING supertype [, ...] ]
[ "{" subcommand; [...] "}" ] ;

where subcommand is one of

  CREATE ANNOTATION annotation-name := value
  CREATE LINK link-name ...
  CREATE PROPERTY property-name ...
  CREATE CONSTRAINT constraint-name ...
  CREATE INDEX ON index-expr

CREATE TYPE defines a new object type for use in the current database.

If name is qualified with a module name, then the type is created in that module, otherwise it is created in the current module. The type name must be distinct from that of any existing schema item in the module.

Most sub-commands and options of this command are identical to the SDL object type declaration, with some additional features listed below:

WITH with-item [, ...]

Alias declarations.

The WITH clause allows specifying module aliases that can be referenced by the command. See WITH block for more information.

The following subcommands are allowed in the CREATE TYPE block:

CREATE ANNOTATION annotation-name := value

Set object type annotation-name to value.

See CREATE ANNOTATION for details.

CREATE LINK link-name ...

Define a new link for this object type. See CREATE LINK for details.

CREATE PROPERTY property-name ...

Define a new property for this object type. See CREATE PROPERTY for details.

CREATE CONSTRAINT constraint-name ...

Define a concrete constraint for this object type. See CREATE CONSTRAINT for details.

CREATE INDEX ON index-expr

Define a new index using index-expr for this object type. See CREATE INDEX for details.

Create an object type User:

Copy
CREATE TYPE User {
    CREATE PROPERTY name -> str;
};

Change the definition of an object type.

[ WITH with-item [, ...] ]
ALTER TYPE name
[ "{" subcommand; [...] "}" ] ;

[ WITH with-item [, ...] ]
ALTER TYPE name subcommand ;

where subcommand is one of

  RENAME TO newname
  EXTENDING parent [, ...]
  CREATE ANNOTATION annotation-name := value
  ALTER ANNOTATION annotation-name := value
  DROP ANNOTATION annotation-name
  CREATE LINK link-name ...
  ALTER LINK link-name ...
  DROP LINK link-name ...
  CREATE PROPERTY property-name ...
  ALTER PROPERTY property-name ...
  DROP PROPERTY property-name ...
  CREATE CONSTRAINT constraint-name ...
  ALTER CONSTRAINT constraint-name ...
  DROP CONSTRAINT constraint-name ...
  CREATE INDEX ON index-expr
  DROP INDEX ON index-expr

ALTER TYPE changes the definition of an object type. name must be a name of an existing object type, optionally qualified with a module name.

The following subcommands are allowed in the ALTER TYPE block:

WITH with-item [, ...]

Alias declarations.

The WITH clause allows specifying module aliases that can be referenced by the command. See WITH block for more information.

name

The name (optionally module-qualified) of the type being altered.

EXTENDING parent [, ...]

Alter the supertype list. The full syntax of this subcommand is:

EXTENDING parent [, ...]
   [ FIRST | LAST | BEFORE exparent | AFTER exparent ]

This subcommand makes the type a subtype of the specified list of supertypes. The requirements for the parent-child relationship are the same as when creating an object type.

It is possible to specify the position in the parent list using the following optional keywords:

  • FIRST – insert parent(s) at the beginning of the parent list,

  • LAST – insert parent(s) at the end of the parent list,

  • BEFORE <parent> – insert parent(s) before an existing parent,

  • AFTER <parent> – insert parent(s) after an existing parent.

ALTER ANNOTATION annotation-name;

Alter object type annotation annotation-name. See ALTER ANNOTATION for details.

DROP ANNOTATION annotation-name

Remove object type annotation-name. See DROP ANNOTATION for details.

ALTER LINK link-name ...

Alter the definition of a link for this object type. See ALTER LINK for details.

DROP LINK link-name

Remove a link item from this object type. See DROP LINK for details.

ALTER PROPERTY property-name ...

Alter the definition of a property item for this object type. See ALTER PROPERTY for details.

DROP PROPERTY property-name

Remove a property item from this object type. See DROP PROPERTY for details.

ALTER CONSTRAINT constraint-name ...

Alter the definition of a constraint for this object type. See ALTER CONSTRAINT for details.

DROP CONSTRAINT constraint-name;

Remove a constraint from this object type. See DROP CONSTRAINT for details.

DROP INDEX ON index-expr

Remove an index defined as index-expr from this object type. See DROP INDEX for details.

All the subcommands allowed in the CREATE TYPE block are also valid subcommands for ALTER TYPE block.

Alter the User object type to make name required:

Copy
ALTER TYPE User {
    ALTER PROPERTY name {
        SET REQUIRED;
    }
};

Remove the specified object type from the schema.

DROP TYPE name ;

DROP TYPE removes the specified object type from the schema. schema. All subordinate schema items defined on this type, such as links and indexes, are removed as well.

Remove the User object type:

Copy
DROP TYPE User;
Light
Dark
System