Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Commit fe0473b

Browse files
Merge pull request #28248 from WilliamDAssafMSFT/20230901-tsql-syntax-sp_rename
20230906 sp_rename for fabric tsql
2 parents 6f9f54a + 3cbba2d commit fe0473b

2 files changed

Lines changed: 41 additions & 12 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/22/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 SQL Endpoint](../../includes/applies-to-version/_fabric-se.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: 32 additions & 12 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: 11/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-fabricse-fabricdw](../../includes/applies-to-version/sql-asdb-asa-fabricse-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,15 @@ 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 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.
9098

9199
## Return code values
92100

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

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

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+
115127
## Permissions
116128

117129
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.
@@ -225,7 +237,7 @@ CK_Employee_SickLeaveHours HumanResources CHECK_CONSTRAINT
225237

226238
### F. Rename statistics
227239

228-
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``.
229241

230242
```sql
231243
CREATE STATISTICS ContactMail1
@@ -242,15 +254,23 @@ EXEC sp_rename 'Person.Person.ContactMail1', 'NewContact','Statistics';
242254
The following example renames the `c1` column in the `table1` table to `col1`.
243255

244256
> [!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.
246258
247259
```sql
248260
CREATE TABLE table1 (c1 INT, c2 INT);
249261
EXEC sp_rename 'table1.c1', 'col1', 'COLUMN';
250262
GO
251263
```
252264

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.
268+
269+
```sql
270+
exec sp_rename @objname = 'dbo.table1', @newname = 'table2', @objtype = 'OBJECT';
271+
```
272+
273+
## Related content
254274

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

0 commit comments

Comments
 (0)