When CREATE TYPE is used to create a CLR user-defined type, the database compatibility must be 90.
The class of the assembly that is referenced in assembly_name, together with its methods, should satisfy all the requirements for implementing a user-defined type in SQL Server. For more information about these requirements, see CLR User-Defined Types.
Additional considerations include the following:
-
The class can have overloaded methods, but these methods can be called only from within managed code, not from Transact-SQL.
-
Any static members must be declared as const or readonly if assembly_name is SAFE or EXTERNAL_ACCESS.
Within a database, there can be only one user-defined type registered against any specified type that has been uploaded in SQL Server from the CLR. If a user-defined type is created on a CLR type for which a user-defined type already exists in the database, CREATE TYPE fails with an error. This restriction is required to avoid ambiguity during SQL Type resolution if a CLR type can be mapped to more than one user-defined type.
If any mutator method in the type does not return void, the CREATE TYPE statement does not execute.
To modify a user-defined type, you must drop the type by using a DROP TYPE statement and then re-create it.
Unlike user-defined types that are created by using sp_addtype, the public database role is not automatically granted REFERENCES permission on types that are created by using CREATE TYPE. This permission must be granted separately.
In user-defined table types, structured user-defined types that are used in column_name <data type> are part of the database schema scope in which the table type is defined. To access structured user-defined types in a different scope within the database, use two-part names.
In user-defined table types, the primary key on computed columns must be PERSISTED and NOT NULL.