Object Types
This section describes the DDL commands pertaining to object types.
Create type
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
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
:
create type User {
create property name -> str;
};
Alter type
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
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:
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.
Examples
Alter the User
object type to make name
required:
alter type User {
alter property name {
set required;
}
};
Drop type
Remove the specified object type from the schema.
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:
drop type User;
︙
See also |