2

"RuntimeError: Catalog Error: Can only modify view with ALTER VIEW statement" When trying to rename a column while using DataFrame SQL within Deepnote

ALTER TABLE df RENAME COLUMN V41690973 TO cpi;

A screenshot giving some more context enter image description here

2 Answers2

3

You can use the SELECT * EXCLUDE (col_name) syntax in combination with Deepnote's ability to overwrite the variable df from Dataframe SQL to rename a column like this:

SELECT
    col1 as col1_renamed,
    * EXCLUDE (col1)
FROM df

enter image description here

Here's a published reproducible notebook: https://deepnote.com/@the21st/Rename-a-column-using-DataFrame-SQL-1864ef27-a977-4039-bdc5-3b81215a2f2e in case you want to fork it and try it yourself.

the21st
  • 1,012
  • 1
  • 10
  • 24
1

By following way we can Rename Column name in MSSQL

EXEC sp_rename 'TableName.FromColumnaname', 'Tocolumn';  

To change table name

EXEC sp_rename 'FromTableName', 'ToTableName';  

Make sure that have you using anywhere in SP's or Functions it may effect functionality

Upender Reddy
  • 568
  • 3
  • 8