cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Ownership change for table using SQL

Nid-cbs
New Contributor III

It's not possible to use the ALTER TABLE tblname OWNER TO serviceprinc1 command in Azure Databricks, as this isn't supported. I was trying to set a catalog table's ownership, but it resulted in an error. How can I achieve this using a script

7 REPLIES 7

szymon_dybczak
Contributor III

Hi @Nid-cbs ,

Are you sure that you're using correct syntax? According to documentation it should be:

ALTER TABLE table_name SET OWNER TO principal

Nid-cbs
New Contributor III

ALTER TABLE catalogue.schema.table OWNER TO GUID

the rror is [PARSE_SYNTAX_ERROR] Syntax error at or near 'OWNER'.(line 1, pos 43)

 

I still think that you're using bad synxtax. You're missing SET keyword before OWNER. Try as below:

 

ALTER TABLE catalogue.schema.table SET OWNER TO GUID

 

 

Thanks. Still the same error 

 

[PARSE_SYNTAX_ERROR] Syntax error at or near 'OWNER'.(line 1, pos 35)

filipniziol
New Contributor III

Hi @Nid-cbs ,

It depends on how you are using the code.
Make sure you are using .sql notebook type or %sql magic command, and not spark.sql.
Also, the owner should be wrapped in ` backtick characters:

 

%sql
ALTER TABLE test_table SET OWNER TO `owner`

 

More on that:
https://stackoverflow.com/questions/68804903/databricks-alter-table-owner-to-userid-is-not-working-w...

Nid-cbs
New Contributor III

it turns out that The ALTER TABLE statement in Databricks SQL does not support changing the owner of a table directly.It seems we need to use REST API to do the same 

Thanks for the information. This is very strange though. I'll check it tommorrow. It should work in a notebook with %sql cell.

It won't work if use spark.sql("ALTER TABLE test_table SET OWNER TO `owner_name`") though.

 

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group