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
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!

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!