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

Commit 457e10b

Browse files
authored
Merge pull request #14363 from mzaman1/pdwchangehere
rename column and alter view in APS/PDW
2 parents 8803a04 + 7796916 commit 457e10b

2 files changed

Lines changed: 39 additions & 2 deletions

File tree

docs/t-sql/statements/alter-view-transact-sql.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ author: CarlRabeler
2222
ms.author: carlrab
2323
---
2424
# ALTER VIEW (Transact-SQL)
25-
[!INCLUDE[tsql-appliesto-ss2008-asdb-asdw-xxx-md](../../includes/tsql-appliesto-ss2008-asdb-asdw-xxx-md.md)]
25+
[!INCLUDE[tsql-appliesto-ss2008-all-md](../../includes/tsql-appliesto-ss2008-all-md.md)]
2626

2727
Modifies a previously created view. This includes an indexed view. ALTER VIEW does not affect dependent stored procedures or triggers and does not change permissions.
2828

@@ -42,7 +42,16 @@ AS select_statement
4242
[ SCHEMABINDING ]
4343
[ VIEW_METADATA ]
4444
}
45+
```
46+
4547
```
48+
-- Syntax for Azure Synapse Analytics (SQL DW) and Parallel Data Warehouse
49+
50+
ALTER VIEW [ schema_name . ] view_name [ ( column_name [ ,...n ] ) ]
51+
AS <select_statement>
52+
[;]
53+
54+
```
4655

4756
## Arguments
4857
*schema_name*

docs/t-sql/statements/rename-transact-sql.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ monikerRange: ">= aps-pdw-2016 || = azure-sqldw-latest || = sqlallproducts-allve
1313
# RENAME (Transact-SQL)
1414
[!INCLUDE[tsql-appliesto-xxxxxx-xxxx-asdw-pdw-md](../../includes/tsql-appliesto-xxxxxx-xxxx-asdw-pdw-md.md)]
1515

16-
Renames a user-created table in [!INCLUDE[ssSDW](../../includes/sssdw-md.md)]. Renames a user-created table or database in [!INCLUDE[ssPDW](../../includes/sspdw-md.md)].
16+
Renames a user-created table in [!INCLUDE[ssSDW](../../includes/sssdw-md.md)]. Renames a user-created table, a column in a user-created table or database in [!INCLUDE[ssPDW](../../includes/sspdw-md.md)].
1717

1818
> [!NOTE]
1919
> To rename a database in [!INCLUDE[ssSDW](../../includes/sssdw-md.md)], use [ALTER DATABASE (Azure SQL Data Warehouse](alter-database-transact-sql.md?view=aps-pdw-2016-au7). To rename a database in Azure SQL Database, use the [ALTER DATABASE (Azure SQL Database)](alter-database-transact-sql.md?view=azuresqldb-mi-current) statement. To rename a database in [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)], use the stored procedure [sp_renamedb](../../relational-databases/system-stored-procedures/sp-renamedb-transact-sql.md).
@@ -39,6 +39,9 @@ RENAME OBJECT [::] [ [ database_name . [ schema_name ] . ] | [ schema_name . ] ]
3939
-- Rename a database
4040
RENAME DATABASE [::] database_name TO new_database_name
4141
[;]
42+
43+
-- Rename a column
44+
RENAME OBJECT [::] [ [ database_name . [schema_name ] ] . ] | [schema_name . ] ] table_name COLUMN column_name TO new_column_name [;]
4245
```
4346

4447
## Arguments
@@ -63,6 +66,12 @@ Change the name of a user-defined database from *database_name* to *new_database
6366
- DWDiagnostics
6467
- DWQueue
6568

69+
70+
RENAME OBJECT [::] [ [*database_name* . [ *schema_name* ] . ] | [ *schema_name* . ] ]*table_name* COLUMN *column_name* TO *new_column_name*
71+
**APPLIES TO:** [!INCLUDE[ssPDW](../../includes/sspdw-md.md)]
72+
73+
Change the name of a column in a table.
74+
6675
## Permissions
6776

6877
To run this command, you need this permission:
@@ -79,12 +88,18 @@ You can't rename an external table, indexes, or views. Instead of renaming, you
7988

8089
You can't rename a table or database while it is in use. Renaming a table requires an exclusive lock on the table. If the table is in use, you may need to terminate sessions that are using the table. To terminate a session, you can use the KILL command. Use KILL cautiously since when a session is terminated any uncommitted work will be rolled back. Sessions in SQL Data Warehouse are prefixed by 'SID'. Include 'SID' and the session number when invoking the KILL command. This example views a list of active or idle sessions and then terminates session 'SID1234'.
8190

91+
### Rename column restrictions
92+
93+
You can't rename a column that is used for the table's distribution. You also can't rename any columns in a temp table.
94+
8295
### Views are not updated
8396

8497
When renaming a database, all views that use the former database name will become invalid. This behavior applies to views both inside and outside the database. For example, if the Sales database is renamed, a view that contains `SELECT * FROM Sales.dbo.table1` will become invalid. To resolve this issue, you can either avoid using three-part names in views, or update the views to reference the new database name.
8598

8699
When renaming a table, views are not updated to reference the new table name. Each view, inside or outside of the database, that references the former table name will become invalid. To resolve this issue, you can update each view to reference the new table name.
87100

101+
When renaming a column, views are not updated to reference the new column name. Views will keep showing the old column name until an alter view is performed. In certain cases, views can become invalid needing a drop and recreate.
102+
88103
## Locking
89104

90105
Renaming a table takes a shared lock on the DATABASE object, a shared lock on the SCHEMA object, and an exclusive lock on the table.
@@ -144,4 +159,17 @@ WHERE status='Active' OR status='Idle';
144159

145160
-- Terminate a session using the session_id.
146161
KILL 'SID1234';
162+
```
163+
164+
### E. Rename a column
165+
166+
**APPLIES TO:** [!INCLUDE[ssPDW](../../includes/sspdw-md.md)]
167+
168+
This example renames the FName column of the Customer table to FirstName.
169+
170+
```sql
171+
-- Rename the Fname column of the customer table
172+
RENAME OBJECT::Customer COLUMN FName TO FirstName;
173+
174+
RENAME OBJECT mydb.dbo.Customer COLUMN FName TO FirstName;
147175
```

0 commit comments

Comments
 (0)