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

Query to know all tables and columns name in delta lake

sudhanshu1
New Contributor III

Hi all,

โ€‹

Does anyone know how to write simple SQL query to get all tables and columns name. In oracle we do ,select * from all tab columns. Similarly in SQL server we do select * from information schema . columns.

โ€‹

Do we have something like this in databricks?

โ€‹

1 REPLY 1

AmanSehgal
Honored Contributor III

To view columns in a table, use SHOW COLUMNS.

%sql
show columns in <schema_name>.<table_name>

To show all the tables in a column, use following PySpark code:

%python
 
schema_name = "default"
tbl_columns = {}
 
# Get all tables in a schema
tables = spark.sql("show tables from {}".format(schema_name)).\
               select('tableName').\
               rdd.map(lambda x : x[0]).\
               collect()
 
 # Get all columns in each table
for table in tables:
  tbl_columns[table]=spark.sql("show columns from {}.{}".format(schema_name,table)).\
              select('col_name').\
              rdd.map(lambda x : x[0]).\
              collect()
 
print(tbl_columns) #print JSON

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