Skip to content

Commit a0baa52

Browse files
20230906 sp_rename for fabric tsql
1 parent 1c0c661 commit a0baa52

2 files changed

Lines changed: 37 additions & 10 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
author: WilliamDAssafMSFT
3+
ms.author: wiassaf
4+
ms.date: 09/01/2023
5+
ms.service: sql
6+
ms.topic: include
7+
---
8+
9+
[!INCLUDE [Applies to](../../includes/applies-md.md)] [!INCLUDE [SQL Server](_ssnoversion.md)] [!INCLUDE [Azure SQL Database](../../includes/applies-to-version/_asdb.md)] [!INCLUDE [Azure Synapse Analytics](../../includes/applies-to-version/_asa.md)] [!INCLUDE [Fabric Data Warehouse](../../includes/applies-to-version/_fabric-dw.md)]

docs/relational-databases/system-stored-procedures/sp-rename-transact-sql.md

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: "Changes the name of a user-created object in the current database.
44
author: markingmyname
55
ms.author: maghan
66
ms.reviewer: randolphwest, maghan
7-
ms.date: 06/29/2023
7+
ms.date: 09/01/2023
88
ms.service: sql
99
ms.subservice: system-objects
1010
ms.topic: "reference"
@@ -18,19 +18,16 @@ helpviewer_keywords:
1818
- "renaming tables"
1919
dev_langs:
2020
- "TSQL"
21-
monikerRange: "=azuresqldb-current || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current || =azure-sqldw-latest"
21+
monikerRange: "=azuresqldb-current || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current || =azure-sqldw-latest || = fabric"
2222
---
2323
# sp_rename (Transact-SQL)
2424

25-
[!INCLUDE [sql-asdb-asa](../../includes/applies-to-version/sql-asdb-asa.md)]
25+
[!INCLUDE [sql-asdb-asa-fabricdw](../../includes/applies-to-version/sql-asdb-asa-fabricdw.md)]
2626

2727
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)]
2828

2929
[!INCLUDE [dnprdnshort](../../includes/dnprdnshort-md.md)] common language runtime (CLR) user-defined type.
3030

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.
33-
3431
[!INCLUDE [synapse-analytics-severless-sql-pools-tsql](Includes/synapse-analytics-severless-sql-pools-tsql.md)]
3532

3633
> [!CAUTION]
@@ -54,6 +51,13 @@ sp_rename [ @objname = ] 'object_name' , [ @newname = ] 'new_name'
5451
, [ @objtype = ] 'COLUMN'
5552
```
5653

54+
Syntax for `sp_rename` in [!INCLUDE [fabric](../../includes/fabric.md)]:
55+
56+
```syntaxsql
57+
sp_rename [ @objname = ] 'object_name' , [ @newname = ] 'new_name'
58+
[ , [ @objtype = ] 'OBJECT' ]
59+
```
60+
5761
## Arguments
5862

5963
#### [ @objname = ] '*object_name*'
@@ -82,11 +86,13 @@ The type of object being renamed. *object_type* is **varchar(13)**, with a defau
8286
| 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. |
8387
| 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). |
8488

85-
#### [ @objtype = ] '*COLUMN*'
86-
8789
**Applies to**: Azure Synapse Analytics
8890

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.
92+
93+
**Applies to**: [!INCLUDE [fabric](../../includes/fabric.md)]
94+
95+
In `sp_rename` for warehouses in [!INCLUDE [fabric](../../includes/fabric.md)], `OBJECT` is the only supported value for *@objtype*.
9096

9197
## Return code values
9298

@@ -112,6 +118,10 @@ In `sp_rename` (preview) for [!INCLUDE [ssazuresynapse](../../includes/ssazuresy
112118

113119
- If you use more than 128 characters for the new name, only the first 128 characters are used and the rest is truncated.
114120

121+
**Applies to** Azure Synapse Analytics:
122+
123+
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.
124+
115125
## Permissions
116126

117127
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.
@@ -250,7 +260,15 @@ EXEC sp_rename 'table1.c1', 'col1', 'COLUMN';
250260
GO
251261
```
252262

253-
## See also
263+
### H. Rename an object
264+
265+
The following example renames the table `dbo.table1` to `dbo.table2`, using the `'OBJECT'` type.
266+
267+
```sql
268+
exec sp_rename @objname = 'dbo.table1', @newname = 'table2', @objtype = 'OBJECT';
269+
```
270+
271+
## Next steps
254272

255273
- [sys.sql_expression_dependencies (Transact-SQL)](../system-catalog-views/sys-sql-expression-dependencies-transact-sql.md)
256274
- [sys.sql_modules (Transact-SQL)](../system-catalog-views/sys-sql-modules-transact-sql.md)

0 commit comments

Comments
 (0)