Name
CREATE/ALTER TYPE Statement
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 |
MySQL | Not supported |
Oracle | Supported, with limitations |
PostgreSQL | Supported, with variations |
SQL Server | Supported, with variations |
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 following syntax 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 type with the name
type_name
.- UNDER
supertype_name
Creates ...
Get SQL in a Nutshell, 3rd 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.