英文:
How do I pull table name with column name list using databricks sql?
问题
我正在使用Azure Databricks INFORMATION_SCHEMA。需要使用SQL列出所有表和列。
我使用SHOW TABLES命令来查看数据库中的所有表。使用SHOW COLUMNS命令来查看表中的所有列。我漏掉了什么?如何使用SQL获取表名和列名信息的组合列表?
英文:
I am using Azure Databricks INFORMATION_Schema. Need list all tables and columns using SQL.
I used SHOW TABLES command for viewing all tables within a database. SHOW COLUMNS command for viewing all columns within a table. What am I missing? How do I get combine list of table name, and column name information using sql?
答案1
得分: 1
Ideally you are using Unity Catalog, in which case Databricks has you covered with a built-in system table containing all table and column information in the system.information_schema
schema.
The system.information_schema.columns
table has information about the columns, but also has the table_name
column that relates it to the table the column is part of.
https://docs.databricks.com/sql/language-manual/sql-ref-information-schema.html
TL;DR With Unity Catalog:
SELECT
CONCAT(table_catalog, '.', table_schema, '.', table_name) AS `table`,
column_name,
data_type
FROM system.information_schema.columns
ORDER BY 1
英文:
Ideally you are using Unity Catalog, in which case Databricks has you covered with a built-in system table containing all table and column information in the system.information_schema
schema.
The system.information_schema.columns
table has information about the columns, but also has the table_name
column that relates it to the table the column is part of.
https://docs.databricks.com/sql/language-manual/sql-ref-information-schema.html
TL;DR With Unity Catalog:
SELECT
CONCAT(table_catalog, '.', table_schema, '.', table_name) AS `table`,
column_name,
data_type
FROM system.information_schema.columns
ORDER BY 1
答案2
得分: 0
以下是您要翻译的内容:
database_list = ["database_1", "database_2"]
for database in database_list:
for row in spark.sql(f"show tables from {database}").collect():
full_table_name = row["database"] + '.' + row["tableName"]
print(full_table_name)
spark.sql(f"describe {full_table_name}").show()
请告诉我如果您需要更多的翻译帮助。
英文:
Example python notebook (without Unity Catalog)
database_list = ["database_1", "database_2"]
for database in database_list:
for row in spark.sql(f"show tables from {database}").collect():
full_table_name = row["database"] + '.' + row["tableName"]
print(full_table_name)
spark.sql(f"describe {full_table_name}").show()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论