Is there a typedef equivalent in Transact-SQL?

Is there a way to smooth data types in T-SQL (SQL Server 2005), a bit like a C typedef? I would like to be able to alias, say, VARCHAR (20), like "my_datatype", so wherever I want to use VARCHAR (20), I could use my_datatype instead.

Synonyms allow you to do similar things for tables, and there are also built-in synonyms for some data types, but AFAICS cannot define your own data type syntax. Does anyone know any different?

+3
source share
4 answers

How 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
+5
source

, , UDD.

+3

For SQL Server 2005, you have an alias and CLR . Both use CREATE TYPE

+2
source

Maybe CREATE TYPE?

+1
source

Source: https://habr.com/ru/post/1732509/


All Articles