azure databricks sql

Vinodh247-1375 11,041 Reputation points

How to run multi-line sql statements in databricks notebook cell? for me I have to generate scripts of 200 tables but the databricks notebook executes and throws out the result only for the last line in the cell.

SHOW CREATE TABLE customer_table
SHOW CREATE TABLE customer_table_1
SHOW CREATE TABLE customer_table_2

Azure Databricks
Azure Databricks
An Apache Spark-based analytics platform optimized for Azure.
1,911 questions
0 comments No comments
{count} votes

Accepted answer
  1. AnnuKumari-MSFT 30,601 Reputation points Microsoft Employee

    Hi @Vinodh247-1375 ,

    Thankyou for using Microsoft Q&A platform and thanks for posting your question.

    As per my understanding, you are trying to run multiple sql queries in a single cell in a databricks notebook. However, it's giving the output of only the last statement in the result section. Please let me know if my understanding is incorrect.

    This is by design . You should consider using one show command in each cell. However, as I see your requirement is to get the create table statement for multiple tables at once. You can consider writing your sql queries in pyspark using spark.sql function and load the query output in a dataframe and display the dataframe.

    Below is the example:

    df = spark.sql("show create table customer_table")  
    df1 = spark.sql("show create table customer_table_1")  
    df2 = spark.sql("show create table customer_table_2")  



    Hope this will help. Please let us know if any further queries.


    • Please don't forget to click on 130616-image.png or upvote 130671-image.png button whenever the information provided helps you.
      Original posters help the community find answers faster by identifying the correct answer. Here is how
    • Want a reminder to come back and check responses? Here is how to subscribe to a notification
    • If you are interested in joining the VM program and help shape the future of Q&A: Here is how you can be part of Q&A Volunteer Moderators
    0 comments No comments

0 additional answers

Sort by: Most helpful