Updates a row of data in a table.
Update-Row [-TableName] <String> [-SchemaName <String>] [-Column] <Hashtable> [-RawColumnValue] [-Where] <String> [<CommonParameters>]
Update-Row [-TableName] <String> [-SchemaName <String>] [-Column] <Hashtable> [-RawColumnValue] -All [<CommonParameters>]
To specify which columns in a row to update, pass a hashtable as a value to the Column
parameter. This hashtable should have keys that map to column names, and the value of each key will be used to update row(s) in the table.
You are required to use a Where
clause so that you don't inadvertently/accidentally update a column in every row in a table to the same value. If you do want to update the value in every row of the database, omit the Where
parameter and add the Force
switch.
Name | Type | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
TableName | String | The name of the table. |
true | false | |
SchemaName | String | The schema name of the table. Default is |
false | false | dbo |
Column | Hashtable | A hashtable of name/value pairs that map to column names/values that will be updated. |
true | false | |
RawColumnValue | SwitchParameter | Don't escape/quote the column value(s). |
false | false | False |
Where | String | A condition to use so that only certain rows are updated. Without a value, you will need to use the |
true | false | |
All | SwitchParameter | Updates all the rows in the table. |
true | false | False |
Update-Row -SchemaName 'rivet' 'Migrations' @{ LastUpdated = (Get-Date -Utc) } -Where 'MigrationID=20130913131104'
Demonstrates how to update the LastUpdated
date in the rivet.Migrations
table for the migration with ID 20130913131104
. Don't do this in real life.
Update-Row -SchemaName 'rivet' 'Migrations' @{ LastUpdated = (Get-Date -Utc) } -Force
Demonstrates how to update the LastUpdated
date for all rows in the rivet.Migrations
table. You really, really don't want to do this in real life.
Update-Row 'Migrations' @{ MigrationID = 'MigrationID + 1' } -Raw -Where 'MigrationID=20130101010101'
Demonstrates how to pass a SQL expression as the value for the column to update: use the -RawColumnValue
switch.