Renames objects (e.g. tables, constraints, keys).
Rename-Object [-SchemaName <String>] [-Name] <String> [-NewName] <String> [<CommonParameters>]
This function wraps the sp_rename
stored procedure, and can be used to rename objects tracked in sys.objects
:
Use Rename-Index
to rename an index. Use Rename-Column
to rename a column. Use Rename-DataType
to rename a data type.
Name | Type | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
SchemaName | String | The schema of the table. Default is |
false | false | dbo |
Name | String | The current name of the table. |
true | false | |
NewName | String | The new name of the table. |
true | false |
Rename-Object -Name 'FooBar' -NewName 'BarFoo'
Changes the name of the FooBar
table to BarFoo
.
Rename-Object -SchemaName 'fizz' -Name 'Buzz' -NewName 'Baz'
Demonstrates how to rename a table that is in a schema other than dbo
.
Rename-Object 'FK_Foo_Bar' 'FK_Bar_Foo'
Demonstrates how to use Rename-Object
without explicit parameters, and how to rename a foreign key.