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:ย 

How do I get a list of the tables that I personally created?

Barb
New Contributor III

I know that I can get a list of all of the table names in a given 'database' by using (if the 'database' was named "scratch"): show tables from scratch

How do I get a list just like that, but that only lists the tables that I created?

2 REPLIES 2

artsheiko
Honored Contributor

Without Unity Catalog using table history :

  1. Call "SHOW TABLES FROM db_name" to collect all tables names
  2. Loop on tables identifying the table creator using the next command : spark.sql('DESCRIBE HISTORY db_name.table_name').where('operation like "CREATE TABLE%"').select('userName').first()['userName']
  3. Filter the result obtained in p.2 to obtain the target list of tables

Without Unity Catalog using owner field :

  1. Enable table access control for a cluster (https://docs.databricks.com/security/access-control/table-acls/table-acl.html)
  2. Set owner for each table that you need : ALTER TABLE db_name.my_table_name OWNER TO `abc@gmail.com`
  3. Call "SHOW TABLES FROM db_name" to collect all tables names
  4. Loop on tables identifying the table owner spark.sql('DESCRIBE EXTENDED db_name.table_name').filter('col_name = "Owner" and data_type = "abc@gmail.com"')
  5. Filter the result obtained in p.4 to obtain the target list of tables

With Unity Catalog tables, you can use created_by or table_owner column from information_schema.tables :

SELECT *
FROM my_unity_catalog_name.information_schema.tables
WHERE created_by LIKE '%my_username_name_part%'

Vidula
Honored Contributor

Hi @Barb Krienkeโ€‹ 

Hope all is well! Just wanted to check in if you were able to resolve your issue and would you be happy to share the solution or mark an answer as best? Else please let us know if you need more help. 

We'd love to hear from you.

Thanks!

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