Add-Synonym

Creates a synonym.

Syntax

Add-Synonym [-Name] <String> [-SchemaName <String>] [-TargetDatabaseName <String>] [-TargetSchemaName <String>] [-TargetObjectName] <String> [<CommonParameters>]

Description

SQL Server lets you create synonyms so you can reference an object with a different name, or reference an object in another database with a local name.

Related Commands

Parameters

Name Type Description Required? Pipeline Input Default Value
Name String

The name of the synonym.

true false
SchemaName String

The name of the schema where the synonym should be created.

false false dbo
TargetDatabaseName String

The database where the target object is located. Defaults to the current database.

false false
TargetSchemaName String

The scheme of the target object. Defaults to dbo.

false false dbo
TargetObjectName String

The target object's name the synonym will refer to.

true false

EXAMPLE 1

Add-Synonym -Name 'Buzz' -TargetObjectName 'Fizz'

Creates a synonym called Buzz to the object Fizz.

EXAMPLE 2

Add-Synonym -SchemaName 'fiz' -Name 'Buzz' -TargetSchemaName 'baz' -TargetObjectName 'Buzz'

Demonstrates how to create a synonym in a different schema. Creates a synonym to the baz.Buzz object so that it can referenced as fiz.Buzz.

EXAMPLE 3

Add-Synonym -Name 'Buzz' -TargetDatabaseName 'Fizzy' -TargetObjectName 'Buzz'

Demonstrates how to create a synonym to an object in a different database.