You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[!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
-
## <aname="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)].
36
21
37
22
### <aname="Security"></a> Security
38
23
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
+
## <aname="SSMSProcedure"></a> Use SQL Server Management Studio
39
26
40
-
#### <aname="Permissions"></a> Permissions
41
-
42
-
## <aname="SSMSProcedure"></a> Using SQL Server Management Studio
43
-
44
-
#### To Create a Synonym
27
+
### Create a Synonym
45
28
46
29
1. In **Object Explorer**, expand the database where you want to create your new view.
47
30
48
-
2. Right-click the **Synonyms** folder, then click**New Synonym...**.
31
+
2. Right-click the **Synonyms** folder, then select**New Synonym...**.
49
32
50
33
3. In the **Add Synonym** dialog box, enter the following information.
Type the name of the object to which the synonym refers.
72
55
73
-
## <aname="TsqlProcedure"></a> Using Transact-SQL
56
+
## <aname="TsqlProcedure"></a> Use Transact-SQL
74
57
75
-
#### To Create a Synonym
58
+
###Create a Synonym
76
59
77
60
1. Connect to the [!INCLUDE[ssDE](../../includes/ssde-md.md)].
78
61
79
-
2. From the Standard bar, click**New Query**.
62
+
2. From the Standard bar, select**New Query**.
80
63
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**.
82
65
83
66
### <aname="TsqlExample"></a> Example (Transact-SQL)
84
67
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.
85
68
86
-
```
69
+
```sql
87
70
USE tempdb;
88
71
GO
89
72
CREATE SYNONYM MyAddressType
@@ -93,7 +76,7 @@ GO
93
76
94
77
The following example inserts a row into the base table that is referenced by the `MyAddressType` synonym.
95
78
96
-
```
79
+
```sql
97
80
USE tempdb;
98
81
GO
99
82
INSERT INTO MyAddressType (Name)
@@ -103,11 +86,13 @@ GO
103
86
104
87
The following example demonstrates how a synonym can be referenced in dynamic SQL.
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.
66
70
67
-
*synonym_name*
71
+
####*synonym_name*
68
72
Is the name of the new synonym.
69
73
70
-
*server_name*
74
+
####*server_name*
71
75
**Applies to**: [!INCLUDE[ssKatmai](../../includes/sskatmai-md.md)] and later.
72
76
73
77
Is the name of the server on which base object is located.
74
78
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.
77
81
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.
80
84
81
-
*object_name*
85
+
####*object_name*
82
86
Is the name of the base object that the synonym references.
83
87
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 #.
85
89
86
90
## Remarks
87
91
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.
In the following example, the base object, `Contact`, resides on a remote server named `Server_Remote`.
155
159
156
160
**Applies to**: [!INCLUDE[ssKatmai](../../includes/sskatmai-md.md)] and later.
@@ -164,8 +168,8 @@ CREATE SYNONYM MyEmployee FOR Server_Remote.AdventureWorks2012.HumanResources.Em
164
168
GO
165
169
```
166
170
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.
169
173
170
174
```sql
171
175
-- Creating the dbo.OrderDozen function
@@ -198,9 +202,13 @@ SET @Amt = 15;
198
202
SELECT @Amt AS OriginalOrder, dbo.CorrectOrder(@Amt) AS ModifiedOrder;
0 commit comments