Name
CREATE/ALTER TYPE Statement
Synopsis
The CREATE TYPE statement allows you to create a user-defined type (UDT); that is, a user-defined datatype or “class” in object-oriented terms. UDTs extend SQL capabilities into the realm of object-oriented programming by allowing inheritance and other object-oriented features. You can also create something called typed tables with the CREATE TABLE statement using a previously created type made with the CREATE TYPE statement. Typed tables are based on UDTs and are equivalent to “instantiated classes” from object-oriented programming.
Platform |
Command |
DB2 |
Supported, with variations |
MySQL |
Not supported |
Oracle |
Supported, with limitations |
PostgreSQL |
Supported, with variations |
SQL Server |
Not supported |
SQL2003 Syntax
CREATE TYPEtype_name
[UNDERsupertype_name
] [AS [new_udt_name
]datatype
[attribute
] [,...] {[REFERENCES ARE [NOT] CHECKED [ON DELETE {NO ACTION | CASCADE | RESTRICT | SET NULL | SET DEFAULT} ] ] | [DEFAULTvalue
] | [COLLATEcollation_name
] } ] [ [NOT] INSTANTIABLE] [ [NOT] FINAL] [REF IS SYTEM GENERATED | REF USINGdatatype
[CAST {(SOURCE AS REF) | (REF AS SOURCE) WITHidentifier
} ] | REFnew_udt_name
[,...] } ] [CAST {(SOURCE AS DISTINCT) | (DISTINCT AS SOURCE)} WITHidentifier
] [method_definition
[,...] ]
The syntax below alters an existing user-defined datatype:
ALTER TYPEtype_name
{ADD ATTRIBUTEtype_definition
| DROP ATTRIBUTEtype_name
}
Keywords
- {CREATE | ALTER} TYPE
type_name
Creates a new type or alters an existing ...
Get SQL in a Nutshell, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.