Creates a new table in the database.


Add-Table [-Name] <String> [-SchemaName <String>] [-Column] <ScriptBlock> [-FileGroup <String>] [-TextImageFileGroup <String>] [-FileStreamFileGroup <String>] [-Option <String[]>] [-Description <String>] [<CommonParameters>]
Add-Table [-Name] <String> [-SchemaName <String>] -FileTable [-FileGroup <String>] [-TextImageFileGroup <String>] [-FileStreamFileGroup <String>] [-Option <String[]>] [-Description <String>] [<CommonParameters>]


The column's for the table should be created and returned in a script block, which is passed as the value of the Column parameter. For example,

Add-Table 'Suits' {
    Int 'id' -Identity
    TinyInt 'pieces -NotNull
    VarChar 'color' -NotNull

Related Commands


Name Type Description Required? Pipeline Input Default Value
Name String

The name of the table.

true false
SchemaName String

The table's schema. Defaults to 'dbo'.

false false dbo
Column ScriptBlock

A script block that returns the table's columns.

true false
FileTable SwitchParameter

Creates a FileTable table.

true false False
FileGroup String

Specifies the partition scheme or filegroup on which the table is stored, e.g. ON $FileGroup

false false
TextImageFileGroup String

The filegroup where text, ntext, image, xml, varchar(max), nvarchar(max), and varbinary(max) columns are stored. The table has to have one of those columns. For example, TEXTIMAGE_ON $TextImageFileGroup.

false false
FileStreamFileGroup String

Specifies the filegroup for FILESTREAM data, e.g. FILESTREAM_ON $FileStreamFileGroup.

false false
Option String[]

Specifies one or more table options.

false false
Description String

A description of the table.

false false


Add-Table -Name 'Ties' -Column { VarChar 'color' -NotNull }

Creates a Ties table with a single column for each tie's color. Pretty!