Home > Mobile >  How do I rename a column in Dataframe SQL?
How do I rename a column in Dataframe SQL?

Time:06-30

"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

CodePudding user response:

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.

CodePudding user response:

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

  • Related