Rename-Object

Renames objects (e.g. tables, constraints, keys).

Syntax

Rename-Object [-SchemaName <String>] [-Name] <String> [-NewName] <String> [<CommonParameters>]

Description

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.

Related Commands

Parameters

Name Type Description Required? Pipeline Input Default Value
SchemaName String

The schema of the table. Default is dbo.

false false dbo
Name String

The current name of the table.

true false
NewName String

The new name of the table.

true false

EXAMPLE 1

Rename-Object -Name 'FooBar' -NewName 'BarFoo'

Changes the name of the FooBar table to BarFoo.

EXAMPLE 2

Rename-Object -SchemaName 'fizz' -Name 'Buzz' -NewName 'Baz'

Demonstrates how to rename a table that is in a schema other than dbo.

EXAMPLE 3

Rename-Object 'FK_Foo_Bar' 'FK_Bar_Foo'

Demonstrates how to use Rename-Object without explicit parameters, and how to rename a foreign key.