Creates a user-defined datatype.
sp_addtype typename, phystype [(length) | (precision [, scale])] [, "identity" | nulltype]
The char, varchar, unichar, univarchar, nchar, nvarchar, binary, and varbinary datatypes expect a length in parentheses. If you do not supply one, the SAP ASE server uses the default length of 1 character.
The float datatype expects a binary precision in parentheses. If you do not supply one, the SAP ASE server uses the default precision for your platform.
The numeric and decimal datatypes expect a decimal precision and scale, in parentheses and separated by a comma. If you do not supply them, the SAP ASE server uses a default precision of 18 and a scale of 0.
Enclose physical types that include punctuation, such as parentheses or commas, within single or double quotes.
IDENTITY columns store sequential numbers, such as invoice numbers or employee numbers, that are generated by the SAP ASE server. The value of the IDENTITY column uniquely identifies each row in a table. IDENTITY columns are not updatable and do not allow null values.
If you omit both the IDENTITY property and the nulltype, the SAP ASE server creates the datatype using the null mode defined for the database. By default, datatypes for which no nulltype is specified are created NOT NULL (that is, null values are not allowed and explicit entries are required). For compliance to the SQL standards, use the sp_dboption system procedure to set the allow nulls by default option to true. This changes the database’s null mode to NULL.
sp_addtype ssn, "varchar(11)"
sp_addtype birthday, "datetime", null
sp_addtype temp52, "numeric(5,2)"
sp_addtype "row_id", "numeric(10,0)", "identity"
sp_addtype systype, sysname
sp_addtype creates a user-defined datatype and adds it to the systypes system table. Once a user-defined datatype is created, you can use it in create table and alter table statements and bind defaults and rules to it.
Build each user-defined datatype in terms of one of the SAP ASE-supplied datatypes, specifying the length or the precision and scale, as appropriate. You cannot override the length, precision, or scale in a create table or alter table statement.
A user-defined datatype name must be unique in the database, but user-defined datatypes with different names can have the same definitions.
If nchar or nvarchar is specified as the phystype, the maximum length of columns created with the new type is the length specified in sp_addtype multiplied by the value of @@ncharsize at the time the type was added.
If unichar or univarchar is specified as the phystype, the maximum length of columns created with the new type is the length specified in sp_addtype multiplied by the value of 2 at the time the type was added.
Each system type has a hierarchy, stored in the systypes system table. User-defined datatypes have the same datatype hierarchy as the physical types on which they are based. In a mixed-mode expression, all types are converted to a common type, the type with the lowest hierarchy.
select name, hierarchy from systypes order by hierarchy
create table new_table (id_col IdentType)
create table new_table (id_col IdentType identity)
create table new_table (id_col IdentType not null)
Types specified as NOT NULL can be used to create NULL or IDENTITY columns.
Types specified as NULL can be used to create NOT NULL columns, but not to create IDENTITY columns.
create default, create rule, create table in Reference Manual: Commands
User-Defined Datatypes in Reference Manual: Building Blocks
Any user can execute sp_addtype. Permission checks do not differ based on the granular permissions settings.
Values in event and extrainfo columns from the sysaudits table are:
Information | Values |
---|---|
Event | 38 |
Audit option | exec_procedure |
Command or access audited | Execution of a procedure |
Information in extrainfo |
|