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
Changes the name of a user-created object in the current database. This object can be a table, index, column, alias data type, or [!INCLUDE [msCoName](../../includes/msconame-md.md)]
28
28
29
29
[!INCLUDE [dnprdnshort](../../includes/dnprdnshort-md.md)] common language runtime (CLR) user-defined type.
30
30
31
-
> [!NOTE]
32
-
> In [!INCLUDE [ssazuresynapse](../../includes/ssazuresynapse-md.md)], `sp_rename` is in **Preview** for dedicated SQL pools and can only be used to rename a COLUMN in a user object.
@@ -82,11 +86,15 @@ The type of object being renamed. *object_type* is **varchar(13)**, with a defau
82
86
| STATISTICS |**Applies to**: [!INCLUDE [ssSQL11](../../includes/sssql11-md.md)] and later and [!INCLUDE [ssazure-sqldb](../../includes/ssazure-sqldb.md)].<br /><br />Statistics created explicitly by a user or created implicitly with an index. Renaming the statistics of an index automatically renames the index as well. |
83
87
| USERDATATYPE | A [CLR user-defined type](../clr-integration-database-objects-user-defined-types/clr-user-defined-types.md) added by executing [CREATE TYPE](../../t-sql/statements/create-type-transact-sql.md) or [sp_addtype](sp-addtype-transact-sql.md). |
84
88
85
-
#### [@objtype = ] '*COLUMN*'
86
-
87
89
**Applies to**: Azure Synapse Analytics
88
90
89
-
In `sp_rename` (preview) for [!INCLUDE [ssazuresynapse](../../includes/ssazuresynapse-md.md)], *COLUMN* is a mandatory parameter specifying that the object type to be renamed is a column. It's a **varchar(13)** with no default value and must always be included in the `sp_rename` (preview) statement. A column can only be renamed if it's not a distribution column.
91
+
In `sp_rename` (preview) for [!INCLUDE [ssazuresynapse](../../includes/ssazuresynapse-md.md)], `COLUMN` is a mandatory value specifying that the object type to be renamed is a column, and must always be included in the `sp_rename` statement. A column can only be renamed if it's not a distribution column.
In `sp_rename` for the Warehouse in [!INCLUDE [fabric](../../includes/fabric.md)], `OBJECT` is the only supported value for *@objtype*.
96
+
97
+
In `sp_rename` for the SQL Endpoint in [!INCLUDE [fabric](../../includes/fabric.md)], `OBJECT` is the only supported value for *@objtype*. Tables cannot be renamed.
90
98
91
99
## Return code values
92
100
@@ -112,6 +120,10 @@ In `sp_rename` (preview) for [!INCLUDE [ssazuresynapse](../../includes/ssazuresy
112
120
113
121
- If you use more than 128 characters for the new name, only the first 128 characters are used and the rest is truncated.
114
122
123
+
**Applies to** Azure Synapse Analytics:
124
+
125
+
In [!INCLUDE [ssazuresynapse](../../includes/ssazuresynapse-md.md)], `sp_rename` is in **Preview** for dedicated SQL pools and can only be used to rename a `'COLUMN'` in a user object.
126
+
115
127
## Permissions
116
128
117
129
To rename objects, columns, and indexes, requires ALTER permission on the object. To rename user types, requires CONTROL permission on the type. To rename a database, requires membership in the **sysadmin** or **dbcreator** fixed server roles. To rename a ledger table, ALTER LEDGER permission is required.
The following example creates a statistics object named contactMail1 and then renames the statistic to NewContact by using `sp_rename`. When you rename statistics, the object must be specified in the format schema.table.statistics_name.
240
+
The following example creates a statistics object named `contactMail1` and then renames the statistic to `NewContact` by using `sp_rename`. When you rename statistics, the object must be specified in the format `schema.table.statistics_name``.
The following example renames the `c1` column in the `table1` table to `col1`.
243
255
244
256
> [!NOTE]
245
-
> This [!INCLUDE [ssazuresynapse](../../includes/ssazuresynapse-md.md)] feature is still in preview for dedicated SQL pools and is currently available only for objects in the **dbo** schema.
257
+
> This [!INCLUDE [ssazuresynapse](../../includes/ssazuresynapse-md.md)] feature is still in preview for dedicated SQL pools and is currently available only for objects in the `dbo` schema.
246
258
247
259
```sql
248
260
CREATETABLEtable1 (c1 INT, c2 INT);
249
261
EXEC sp_rename 'table1.c1', 'col1', 'COLUMN';
250
262
GO
251
263
```
252
264
253
-
## See also
265
+
### H. Rename an object
266
+
267
+
The following example renames the table `dbo.table1` to `dbo.table2`, using the `'OBJECT'` type.
0 commit comments