< Back

New-DbaDbTable

Mon Jan 13, 2020 12:55 pm

NAME New-DbaDbTable



SYNOPSIS

Creates a new table in a database





SYNTAX

New-DbaDbTable [[-SqlInstance] <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>] [[-SqlCredential]

<Pscredential>] [[-Database] <System.String[]>] [[-Name] <String>] [[-Schema] <String>] [[-ColumnMap]

<System.Collections.Hashtable[]>] [[-ColumnObject] <Microsoft.SqlServer.Management.Smo.Column[]>]

[-AnsiNullsStatus <Switch>] [-ChangeTrackingEnabled <Switch>] [[-DataSourceName] <String>] [[-Durability]

<Microsoft.SqlServer.Management.Smo.DurabilityType>] [[-ExternalTableDistribution]

<Microsoft.SqlServer.Management.Smo.ExternalTableDistributionType>] [[-FileFormatName] <String>] [[-FileGroup]

<String>] [[-FileStreamFileGroup] <String>] [[-FileStreamPartitionScheme] <String>] [[-FileTableDirectoryName]

<String>] [[-FileTableNameColumnCollation] <String>] [-FileTableNamespaceEnabled <Switch>] [[-HistoryTableName]

<String>] [[-HistoryTableSchema] <String>] [-IsExternal <Switch>] [-IsFileTable <Switch>] [-IsMemoryOptimized

<Switch>] [-IsSystemVersioned <Switch>] [[-Location] <String>] [[-LockEscalation]

<Microsoft.SqlServer.Management.Smo.LockEscalationType>] [[-Owner] <String>] [[-PartitionScheme] <String>]

[-QuotedIdentifierStatus <Switch>] [[-RejectSampleValue] <Double>] [[-RejectType]

<Microsoft.SqlServer.Management.Smo.ExternalTableRejectType>] [[-RejectValue] <Double>]

[[-RemoteDataArchiveDataMigrationState] <Microsoft.SqlServer.Management.Smo.RemoteDataArchiveMigrationState>]

[-RemoteDataArchiveEnabled <Switch>] [[-RemoteDataArchiveFilterPredicate] <String>] [[-RemoteObjectName] <String>]

[[-RemoteSchemaName] <String>] [[-RemoteTableName] <String>] [-RemoteTableProvisioned <Switch>]

[[-ShardingColumnName] <String>] [[-TextFileGroup] <String>] [-TrackColumnsUpdatedEnabled <Switch>]

[[-HistoryRetentionPeriod] <Int>] [[-HistoryRetentionPeriodUnit]

<Microsoft.SqlServer.Management.Smo.TemporalHistoryRetentionPeriodUnit>] [[-DwTableDistribution]

<Microsoft.SqlServer.Management.Smo.DwTableDistributionType>] [[-RejectedRowLocation] <String>]

[-OnlineHeapOperation <Switch>] [[-LowPriorityMaxDuration] <Int>] [-DataConsistencyCheck <Switch>]

[[-LowPriorityAbortAfterWait] <Microsoft.SqlServer.Management.Smo.AbortAfterWait>] [[-MaximumDegreeOfParallelism]

<Int>] [-IsNode <Switch>] [-IsEdge <Switch>] [-IsVarDecimalStorageFormatEnabled <Switch>] [[-InputObject]

<Microsoft.SqlServer.Management.Smo.Database[]>] [-EnableException <Switch>] [<CommonParameters>]





DESCRIPTION

Creates a new table in a database





PARAMETERS

-AnsiNullsStatus [<Switch>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-ChangeTrackingEnabled [<Switch>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-ColumnMap [<System.Collections.Hashtable[]>]

Hashtable for easy column creation. Looks like this:



# Create collection

$cols = @()



# Add columns to collection

$cols += @{

Name = 'test'

Type = 'varchar'

MaxLength = 20

Nullable = $true

}

$cols += @{

Name = 'test2'

Type = 'int'

Nullable = $false

}

$cols += @{

Name = 'test3'

Type = 'decimal'

MaxLength = 9

Nullable = $true

}

$cols += @{

Name = 'test4'

Type = 'decimal'

Precision = 8

Scale = 2

Nullable = $false

}



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-ColumnObject [<Microsoft.SqlServer.Management.Smo.Column[]>]

If you want to get fancy, you can build your own column objects and pass them in



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Database [<System.String[]>]

The database or databases where the table will be created



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-DataConsistencyCheck [<Switch>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-DataSourceName [<String>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Durability [<Microsoft.SqlServer.Management.Smo.DurabilityType>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-DwTableDistribution [<Microsoft.SqlServer.Management.Smo.DwTableDistributionType>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-EnableException [<Switch>]

By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.

This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables

advanced scripting.

Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own

try/catch.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-ExternalTableDistribution [<Microsoft.SqlServer.Management.Smo.ExternalTableDistributionType>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-FileFormatName [<String>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-FileGroup [<String>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-FileStreamFileGroup [<String>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-FileStreamPartitionScheme [<String>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-FileTableDirectoryName [<String>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-FileTableNameColumnCollation [<String>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-FileTableNamespaceEnabled [<Switch>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-HistoryRetentionPeriod [<Int>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-HistoryRetentionPeriodUnit [<Microsoft.SqlServer.Management.Smo.TemporalHistoryRetentionPeriodUnit>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-HistoryTableName [<String>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-HistoryTableSchema [<String>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-InputObject [<Microsoft.SqlServer.Management.Smo.Database[]>]

Allows piped input from Get-DbaDatabase



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-IsEdge [<Switch>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-IsExternal [<Switch>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-IsFileTable [<Switch>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-IsMemoryOptimized [<Switch>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-IsNode [<Switch>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-IsSystemVersioned [<Switch>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-IsVarDecimalStorageFormatEnabled [<Switch>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Location [<String>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-LockEscalation [<Microsoft.SqlServer.Management.Smo.LockEscalationType>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-LowPriorityAbortAfterWait [<Microsoft.SqlServer.Management.Smo.AbortAfterWait>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-LowPriorityMaxDuration [<Int>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-MaximumDegreeOfParallelism [<Int>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Name [<String>]

The name of the table



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-OnlineHeapOperation [<Switch>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Owner [<String>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-PartitionScheme [<String>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-QuotedIdentifierStatus [<Switch>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-RejectedRowLocation [<String>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-RejectSampleValue [<Double>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-RejectType [<Microsoft.SqlServer.Management.Smo.ExternalTableRejectType>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-RejectValue [<Double>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-RemoteDataArchiveDataMigrationState [<Microsoft.SqlServer.Management.Smo.RemoteDataArchiveMigrationState>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-RemoteDataArchiveEnabled [<Switch>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-RemoteDataArchiveFilterPredicate [<String>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-RemoteObjectName [<String>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-RemoteSchemaName [<String>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-RemoteTableName [<String>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-RemoteTableProvisioned [<Switch>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Schema [<String>]

The schema for the table, defaults to dbo



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-ShardingColumnName [<String>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SqlCredential [<Pscredential>]

Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).



Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory -

Integrated are all supported.



For MFA support, please use Connect-DbaInstance.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SqlInstance [<Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>]

The target SQL Server instance or instances.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-TextFileGroup [<String>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-TrackColumnsUpdatedEnabled [<Switch>]

No information provided by Microsoft



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



NOTES





Tags: table

Author: Chrissy LeMaire (@cl)

Website: https://dbatools.io

Copyright: (c) 2019 by dbatools, licensed under MIT

License: MIT https://opensource.org/licenses/MIT



-------------------------- EXAMPLE 1 --------------------------



PS C:\\>$col = @{



>> Name = 'test'

>> Type = 'varchar'

>> MaxLength = 20

>> Nullable = $true

>> }

PS C:\\> New-DbaDbTable -SqlInstance sql2017 -Database tempdb -Name testtable -ColumnMap $col



Creates a new table on sql2017 in tempdb witht he name testtable and one column



RELATED LINKS

https://dbatools.io/Get-Table