Creates a column object of an explicit datatype which can be used with the Add-Table
or Update-Table
migrations.
New-Column [-Name] <String> [-DataType] <String> [-Sparse] [-Default <Object>] [-Description <String>] [<CommonParameters>]
New-Column [-Name] <String> [-DataType] <String> [-NotNull] [-Default <Object>] [-Description <String>] [<CommonParameters>]
Use this function in the Column
script block for Add-Table
:
Add-Table 'Members' {
New-Column 'Birthday' 'datetime'
}
This column is useful for creating columns of custom types or types for which Rivet doesn't have a specific function.
Returns an object that can be used when adding columns or creating tables to get the SQL needed to create that column.
Name | Type | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
Name | String | The Name of the new column. |
true | false | |
DataType | String | The datatype of the new column, including precision/scale/size specifiers. |
true | false | |
Sparse | SwitchParameter | Optimizes the column storage for null values. Cannot be used with the |
false | false | False |
NotNull | SwitchParameter | Makes the column not nullable. Canno be used with the |
false | false | False |
Default | Object | A SQL Server expression for the column's default value. |
false | false | |
Description | String | A description of the column. |
false | false |
Add-Table 'Members' { New-Column 'Birthday' 'datetime' -NotNull }
Demonstrates how to create a required datetime
column.
Add-Table 'Members' { New-Column 'Birthday' 'float(7)' -NotNull }
Demonstrates that the value of the DataType
parameter should also include any precision/scale/size specifiers.
Add-Table 'Members' { New-Column 'Birthday' 'datetime' -Sparse }
Demonstrate show to create a nullable, sparse datetime
column when adding a new table.
Add-Table 'Members' { New-Column 'Birthday' 'datetime' -NotNull -Default 'getdate()' }
Demonstrates how to create a date column with a default value, in this case the current date. (You alwyas use UTC dates, right?) Probably not a great example, setting someone's birthday to the current date. Reasons are left as an exercise for the reader.
Add-Table 'Members' { New-Column 'Birthday' 'datetime' -Description 'The members birthday.' }
Demonstrates how to create an optional date column with a description.