cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
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
Valued Contributor III
Valued Contributor III

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!

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.