SQL Server Alias Datatypes

Overview

The INFORMATION_SCHEMA.COLUMN_DOMAIN_USAGE view allows you to get information about alias data types that are used for columns. By default, it shows this information for every single table and view in the database that uses an alias data type.

Explanation

This view can be called from any of the databases in an instance of SQL Server and will return the results for the data within that particular database.

The columns that this view returns are as follows:

Column nameData typeDescription
DOMAIN_CATALOGnvarchar(128) Database in which the alias data type exists.
DOMAIN_SCHEMAnvarchar(128)Name of schema that contains the alias data type.
DOMAIN_NAMEsysname Alias data type.
TABLE_CATALOGnvarchar(128)Table qualifier.
TABLE_SCHEMAnvarchar(128) Table owner.
TABLE_NAMEsysname Table in which the alias data type is used.
COLUMN_NAMEsysname Column using the alias data type.

Here is an example of data that was pulled from the AdventureWorks database.  This data was pulled using this query:

SELECT * FROM INFORMATION_SCHEMA.COLUMN_DOMAIN_USAGE

In the results below, we can see that the data type “Name” in the DOMAIN_NAME column is used in several tables for columns ReviewerName (ProductReview) and Name (AddressType, ProductSubcategory, UnitMeasure).

n8
n9

To see the underlying data types for these aliased data types, you can use this query:

SELECT DISTINCT DOMAIN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH
FROM INFORMATION_SCHEMA.COLUMNS
WHERE DOMAIN_NAME IS NOT NULL

Leave a Reply

Your email address will not be published. Required fields are marked *