Skip to content

Commit 10b0521

Browse files
20220201 refresh synonym articles
1 parent 4aa72d1 commit 10b0521

2 files changed

Lines changed: 52 additions & 59 deletions

File tree

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
description: "Create Synonyms"
3-
title: "Create Synonyms | Microsoft Docs"
3+
title: "Create Synonyms"
44
ms.custom: ""
5-
ms.date: "03/14/2017"
5+
ms.date: "02/01/2022"
66
ms.prod: sql
77
ms.technology: t-sql
88
ms.topic: conceptual
@@ -11,41 +11,24 @@ f1_keywords:
1111
helpviewer_keywords:
1212
- "creating synonyms"
1313
- "synonyms [SQL Server], creating"
14-
ms.assetid: fedfa7a5-d0b6-4e2b-90f4-a08122958e33
1514
author: markingmyname
1615
ms.author: maghan
1716
monikerRange: "=azuresqldb-current||>=sql-server-2016||>=sql-server-linux-2017||=azuresqldb-mi-current"
1817
---
1918
# Create Synonyms
2019
[!INCLUDE [SQL Server Azure SQL Database](../../includes/applies-to-version/sql-asdb.md)]
21-
This topic describes how to create a synonym in [!INCLUDE[ssnoversion](../../includes/ssnoversion-md.md)] by using [!INCLUDE[ssManStudioFull](../../includes/ssmanstudiofull-md.md)] or [!INCLUDE[tsql](../../includes/tsql-md.md)].
22-
23-
**In This Topic**
24-
25-
- **Before you begin:**
26-
27-
[Security](#Security)
28-
29-
- **To create a synonym, using:**
30-
31-
[SQL Server Management Studio](#SSMSProcedure)
32-
33-
[Transact-SQL](#TsqlProcedure)
34-
35-
## <a name="BeforeYouBegin"></a> Before You Begin
20+
This article describes how to create a synonym in [!INCLUDE[ssnoversion](../../includes/ssnoversion-md.md)] by using [!INCLUDE[ssManStudioFull](../../includes/ssmanstudiofull-md.md)] or [!INCLUDE[tsql](../../includes/tsql-md.md)].
3621

3722
### <a name="Security"></a> Security
3823
To create a synonym in a given schema, a user must have CREATE SYNONYM permission and either own the schema or have ALTER SCHEMA permission. The CREATE SYNONYM permission is a grantable permission.
24+
25+
## <a name="SSMSProcedure"></a> Use SQL Server Management Studio
3926

40-
#### <a name="Permissions"></a> Permissions
41-
42-
## <a name="SSMSProcedure"></a> Using SQL Server Management Studio
43-
44-
#### To Create a Synonym
27+
### Create a Synonym
4528

4629
1. In **Object Explorer**, expand the database where you want to create your new view.
4730

48-
2. Right-click the **Synonyms** folder, then click **New Synonym...**.
31+
2. Right-click the **Synonyms** folder, then select **New Synonym...**.
4932

5033
3. In the **Add Synonym** dialog box, enter the following information.
5134

@@ -70,20 +53,20 @@ monikerRange: "=azuresqldb-current||>=sql-server-2016||>=sql-server-linux-2017||
7053
**Object name**
7154
Type the name of the object to which the synonym refers.
7255

73-
## <a name="TsqlProcedure"></a> Using Transact-SQL
56+
## <a name="TsqlProcedure"></a> Use Transact-SQL
7457

75-
#### To Create a Synonym
58+
### Create a Synonym
7659

7760
1. Connect to the [!INCLUDE[ssDE](../../includes/ssde-md.md)].
7861

79-
2. From the Standard bar, click **New Query**.
62+
2. From the Standard bar, select **New Query**.
8063

81-
3. Copy and paste the following examples into the query window and click **Execute**.
64+
3. Copy and paste the following examples into the query window and select **Execute**.
8265

8366
### <a name="TsqlExample"></a> Example (Transact-SQL)
8467
The following example creates a synonym for an existing table in the [!INCLUDE[ssSampleDBobject](../../includes/sssampledbobject-md.md)] database. The synonym is then used in subsequent examples.
8568

86-
```
69+
```sql
8770
USE tempdb;
8871
GO
8972
CREATE SYNONYM MyAddressType
@@ -93,7 +76,7 @@ GO
9376

9477
The following example inserts a row into the base table that is referenced by the `MyAddressType` synonym.
9578

96-
```
79+
```sql
9780
USE tempdb;
9881
GO
9982
INSERT INTO MyAddressType (Name)
@@ -103,11 +86,13 @@ GO
10386

10487
The following example demonstrates how a synonym can be referenced in dynamic SQL.
10588

106-
```
89+
```sql
10790
USE tempdb;
10891
GO
10992
EXECUTE ('SELECT Name FROM MyAddressType');
11093
GO
11194
```
112-
113-
95+
96+
## Next steps
97+
98+
- [CREATE SYNONYM (Transact-SQL)](../../t-sql/statements/create-synonym-transact-sql.md)

docs/t-sql/statements/create-synonym-transact-sql.md

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
description: "CREATE SYNONYM (Transact-SQL)"
33
title: CREATE SYNONYM (Transact-SQL)
44
ms.custom: ""
5-
ms.date: "04/11/2017"
5+
ms.date: "02/01/2022"
66
ms.prod: sql
77
ms.prod_service: "database-engine, sql-database"
88
ms.reviewer: ""
@@ -20,7 +20,6 @@ helpviewer_keywords:
2020
- "names [SQL Server], synonyms"
2121
- "CREATE SYNONYM statement"
2222
- "synonyms [SQL Server], creating"
23-
ms.assetid: 41313809-e970-449c-bc35-85da2ef96e48
2423
author: WilliamDAssafMSFT
2524
ms.author: wiassaf
2625
---
@@ -42,12 +41,16 @@ CREATE SYNONYM [ schema_name_1. ] synonym_name FOR <object>
4241
4342
<object> :: =
4443
{
45-
[ server_name.[ database_name ] . [ schema_name_2 ].
46-
| database_name . [ schema_name_2 ].| schema_name_2. ] object_name
44+
[
45+
server_name.[database_name].[schema_name_2].
46+
| database_name.[schema_name_2].
47+
| schema_name_2.
48+
]
49+
object_name
4750
}
4851
```
4952

50-
```
53+
```syntaxsql
5154
-- Azure SQL Database Syntax
5255
5356
CREATE SYNONYM [ schema_name_1. ] synonym_name FOR < object >
@@ -61,27 +64,28 @@ CREATE SYNONYM [ schema_name_1. ] synonym_name FOR < object >
6164
[!INCLUDE[sql-server-tsql-previous-offline-documentation](../../includes/sql-server-tsql-previous-offline-documentation.md)]
6265

6366
## Arguments
64-
*schema_name_1*
65-
Specifies the schema in which the synonym is created. If *schema* is not specified, [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] uses the default schema of the current user.
67+
68+
#### *schema_name_1*
69+
Specifies the schema in which the synonym is created. If `schema_name` isn't specified, [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] uses the default schema of the current user.
6670

67-
*synonym_name*
71+
#### *synonym_name*
6872
Is the name of the new synonym.
6973

70-
*server_name*
74+
#### *server_name*
7175
**Applies to**: [!INCLUDE[ssKatmai](../../includes/sskatmai-md.md)] and later.
7276

7377
Is the name of the server on which base object is located.
7478

75-
*database_name*
76-
Is the name of the database in which the base object is located. If *database_name* is not specified, the name of the current database is used.
79+
#### *database_name*
80+
Is the name of the database in which the base object is located. If `database_name` isn't specified, the name of the current database is used.
7781

78-
*schema_name_2*
79-
Is the name of the schema of the base object. If *schema_name* is not specified the default schema of the current user is used.
82+
#### *schema_name_2*
83+
Is the name of the schema of the base object. If `schema_name` isn't specified, the default schema of the current user is used.
8084

81-
*object_name*
85+
#### *object_name*
8286
Is the name of the base object that the synonym references.
8387

84-
Azure SQL Database supports the three-part name format database_name.[schema_name].object_name when the database_name is the current database or the database_name is tempdb and the object_name starts with #.
88+
[!INCLUDE[ssSDSfull](../../includes/sssdsfull-md.md)] supports the three-part name format `database_name.[schema_name].object_name` when the `database_name` is the current database or the `database_name` is `tempdb` and the `object_name` starts with #.
8589

8690
## Remarks
8791
The base object need not exist at synonym create time. [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] checks for the existence of the base object at run time.
@@ -120,7 +124,7 @@ CREATE SYNONYM [ schema_name_1. ] synonym_name FOR < object >
120124
121125
## Examples
122126

123-
### A. Creating a synonym for a local object
127+
### A. Create a synonym for a local object
124128
The following example first creates a synonym for the base object, `Product` in the `AdventureWorks2012` database, and then queries the synonym.
125129

126130
```sql
@@ -138,7 +142,7 @@ GO
138142

139143
[!INCLUDE[ssResult](../../includes/ssresult-md.md)]
140144

141-
```
145+
```output
142146
-----------------------
143147
ProductID Name
144148
----------- --------------------------
@@ -150,7 +154,7 @@ GO
150154
(4 row(s) affected)
151155
```
152156

153-
### B. Creating a synonym to remote object
157+
### B. Create a synonym to remote object
154158
In the following example, the base object, `Contact`, resides on a remote server named `Server_Remote`.
155159

156160
**Applies to**: [!INCLUDE[ssKatmai](../../includes/sskatmai-md.md)] and later.
@@ -164,8 +168,8 @@ CREATE SYNONYM MyEmployee FOR Server_Remote.AdventureWorks2012.HumanResources.Em
164168
GO
165169
```
166170

167-
### C. Creating a synonym for a user-defined function
168-
The following example creates a function named `dbo.OrderDozen` that increases order amounts to an even dozen units. The example then creates the synonym `dbo.CorrectOrder` for the `dbo.OrderDozen` function.
171+
### C. Create a synonym for a user-defined function
172+
The following example creates a function named `dbo.OrderDozen` that increases order amounts to 12 units. The example then creates the synonym `dbo.CorrectOrder` for the `dbo.OrderDozen` function.
169173

170174
```sql
171175
-- Creating the dbo.OrderDozen function
@@ -198,9 +202,13 @@ SET @Amt = 15;
198202
SELECT @Amt AS OriginalOrder, dbo.CorrectOrder(@Amt) AS ModifiedOrder;
199203
```
200204

201-
## See Also
202-
[DROP SYNONYM &#40;Transact-SQL&#41;](../../t-sql/statements/drop-synonym-transact-sql.md)
203-
[GRANT &#40;Transact-SQL&#41;](../../t-sql/statements/grant-transact-sql.md)
204-
[EVENTDATA &#40;Transact-SQL&#41;](../../t-sql/functions/eventdata-transact-sql.md)
205-
206-
205+
## See also
206+
207+
- [DROP SYNONYM &#40;Transact-SQL&#41;](../../t-sql/statements/drop-synonym-transact-sql.md)
208+
- [EVENTDATA &#40;Transact-SQL&#41;](../../t-sql/functions/eventdata-transact-sql.md)
209+
- [GRANT &#40;Transact-SQL&#41;](../../t-sql/statements/grant-transact-sql.md)
210+
- [Synonyms (Database Engine)](../../relational-databases/synonyms/synonyms-database-engine.md)
211+
212+
## Next steps
213+
214+
- [Create Synonyms](../../relational-databases/synonyms/create-synonyms.md)

0 commit comments

Comments
 (0)