Is there any way of aliasing datatypes in T-SQL (SQL Server 2005), a bit like a C typedef? I'd like to be able to alias, say, VARCHAR(20) as 'my_datatype' so that wherever I wish to use VARCHAR(20) I could instead use my_datatype.
Synonyms allow you to do this sort of thing for tables, and there are built-in synonyms for some datatypes too, but AFAICS it is not possible to define your own datatype synonyms. Anyone know any different?
What about this
CREATE TYPE [schema_name.]typename
FROM system_data_type_name [(precision,scale)] [NULL|NOT NULL]
For example
CREATE TYPE CountryCode
FROM char(2) NULL
您正在寻找的是用户定义的数据类型或UDD。
For SQL Server 2005, you have alias and CLR types. Both use CREATE TYPE
或许创造类型?
For PostgreSQL the syntax is a bit different:
CREATE DOMAIN [schema_name.]new_typename
AS existing_typename [any_constraint];
For example:
CREATE DOMAIN CountryCode
AS char(2);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.