Add-DataType

Creates an alias or user-defined type.

Syntax

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>]

Description

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

Parameters

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

EXAMPLE 1

Add-DataType 'GUID' 'uniqueidentifier'

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

EXAMPLE 2

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

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

EXAMPLE 3

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.