New-DateTime2Column

Creates a column object representing an DateTime2 datatype.

Syntax

New-DateTime2Column [-Name] <String> [[-Precision] <Int32>] [-Sparse] [-Default <String>] [-Description <String>] [<CommonParameters>]
New-DateTime2Column [-Name] <String> [[-Precision] <Int32>] -NotNull [-Default <String>] [-Description <String>] [<CommonParameters>]

Description

Use this function in the Column script block for Add-Table:

Add-Table 'Orders' {
    DateTime2 'OrderedAt'
}

ALIASES

Parameters

Name Type Description Required? Pipeline Input Default Value
Name String

The column's name.

true false
Precision Int32

The number of decimal digits that will be stored to the right of the decimal point

false false 0
NotNull SwitchParameter

Don't allow NULL values in this column.

true false False
Sparse SwitchParameter

Store nulls as Sparse.

false false False
Default String

A SQL Server expression for the column's default value

false false
Description String

A description of the column.

false false

EXAMPLE 1

Add-Table 'Orers' { DateTime2 'OrderedAt' }

Demonstrates how to create an optional datetime2 column.

EXAMPLE 2

Add-Table 'Orders' { DateTime2 'OrderedAt' 5 -NotNull }

Demonstrates how to create a required datetime2 column with 5 digits of fractional seconds precision.

EXAMPLE 3

Add-Table 'Orders' { DateTime2 'OrderedAt' -Sparse }

Demonstrate show to create a nullable, sparse datetime2 column when adding a new table.

EXAMPLE 4

Add-Table 'Orders' { DateTime2 'OrderedAt' -NotNull -Default 'getutcdate()' }

Demonstrates how to create a datetime2 column with a default value. You only use UTC dates, right?

EXAMPLE 5

Add-Table 'Orders' { DateTime2 'OrderedAt' -NotNull -Description 'The time the record was created.' }

Demonstrates how to create a datetime2 column with a description.