Creates an alias or user-defined type.


Add-DataType [-SchemaName <String>] [-Name] <String> [-From] <String> [<CommonParameters>]
Add-DataType [-SchemaName <String>] [-Name] <String> -AssemblyName <String> -ClassName <String> [<CommonParameters>]
Add-DataType [-SchemaName <String>] [-Name] <String> -AsTable <ScriptBlock> [-TableConstraint <String[]>] [<CommonParameters>]


There are three different user-defined data types. The first is an alias, from a name you choose to a system datatype. The second is an assembly type, which uses a type stored in a .NET assembly. The third is a table data type, which create a type for a table.

Related Commands


Name Type Description Required? Pipeline Input Default Value
SchemaName String

The schema for the type. Default is dbo.

false false dbo
Name String

The name of the type.

true false
From String

The system type to alias.

true false
AssemblyName String

The name of the assembly for the type's implementation.

true false
ClassName String

The name of the type's class implementation.

true false
AsTable ScriptBlock

A ScriptBlock which returns columns for the table.

true false
TableConstraint String[]

A list of table constraints for a table-based data type.

false false


Add-DataType 'GUID' 'uniqueidentifier'

Demonstrates how to create a new alias data type called GUID which aliases the system uniqueidentifier.


Add-DataType 'Names' -AsTable { varchar 'Name' 50 } -TableConstraint 'primary key'

Demonstrates how to create a new table-based data type.


Add-DataType 'RivetDateTime' -AssemblyName 'Rivet' -ClassName 'Rivet.RivetDateTime'

Demonstrates how to create a RivetDateTime type that references the Rivet.RivetDateTime class. The Rivet assembly must first be registered using create assembly.