Adds new columns or alters existing columns on an existing table.
Update-Table [-Name] <String> [-SchemaName <String>] [-AddColumn <ScriptBlock>] [-UpdateColumn <ScriptBlock>] [-RemoveColumn <String[]>] [<CommonParameters>]
The Update-Table
operation adds, updates, and removes columns from a table. Columns are added, then updated, then removed.
The new columns for the table should be created and returned in a script block, which is passed as the value of the AddColumn
parameter. For example,
Update-Table 'Suits' -AddColumn {
Bit 'HasVest' -NotNull -Default 0
}
The new definitions for existing columns should be created and returned in a script block, which is passed as the value of the UpdateColumn
parameter. For example,
Update-Table 'Suits' -UpdateColumn {
VarChar 'Color' 256 -NotNull
}
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 |
false | false | dbo |
AddColumn | ScriptBlock | A script block that returns the new columns to add to a table. |
false | false | |
UpdateColumn | ScriptBlock | A script block that returns new column definitions for existing columns |
false | false | |
RemoveColumn | String[] | Columns to remove. |
false | false |
Update-Table -Name 'Ties' -AddColumn { VarChar 'Color' 50 -NotNull }
Adds a new Color
column to the Ties
table. Pretty!
Update-Table -Name 'Ties' -UpdateColumn { VarChar 'Color' 100 -NotNull }
Demonstrates how to change the definition of an existing column.
Update-Table -Name 'Ties' -RemoveColumn 'Pattern','Manufacturer'
Demonstrates how to remove columns from a table.