Object Types​

This section describes the DDL commands pertaining to object types.

Create type​

Define a new object type.

  1. [ with with-item [, ...] ]
  2. create [abstract] type name [ extending supertype [, ...] ]
  3. [ "{" subcommand; [...] "}" ] ;
  4. where subcommand is one of
  5. create annotation annotation-name := value
  6. create link link-name ...
  7. create property property-name ...
  8. create constraint constraint-name ...
  9. create index on index-expr

Description​

The command 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.

Parameters​

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.

Examples​

Create an object type User:

  1. create type User {
  2. create property name -> str;
  3. };

Alter type​

Change the definition of an object type.

  1. [ with with-item [, ...] ]
  2. alter type name
  3. [ "{" subcommand; [...] "}" ] ;
  4. [ with with-item [, ...] ]
  5. alter type name subcommand ;
  6. where subcommand is one of
  7. rename to newname
  8. extending parent [, ...]
  9. create annotation annotation-name := value
  10. alter annotation annotation-name := value
  11. drop annotation annotation-name
  12. create link link-name ...
  13. alter link link-name ...
  14. drop link link-name ...
  15. create property property-name ...
  16. alter property property-name ...
  17. drop property property-name ...
  18. create constraint constraint-name ...
  19. alter constraint constraint-name ...
  20. drop constraint constraint-name ...
  21. create index on index-expr
  22. drop index on index-expr

Description​

The command 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.

Parameters​

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:

  1. extending parent [, ...]
  2. [ 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.

Examples​

Alter the User object type to make name required:

  1. alter type User {
  2. alter property name {
  3. set required;
  4. }
  5. };

Drop type​

Remove the specified object type from the schema.

  1. drop type name ;

Description​

The command 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.

Examples​

Remove the User object type:

  1. drop type User;

See also

Schema > Object types

SDL > Object types

Introspection > Object types

Cheatsheets > Object types