JT387
JT387

Reputation: 21

View and edit the create statement of a view in SQL databricks-delta lake

Ive created a SQL view in databricks ie.

create view [database].[view name] as select col1, col2 from [table] 

How do I view and edit that create statement now?

I've tried show create table [database].[view name], which does return the create statement in unformatted text in the result window, which is a pain to reformat, especially if you have comments in the code and its a particularly large and complex query.

Then the only way i can see to edit that view is to copy that text into a new window, make changes and paste it beneath an alter view alter body statement.

Is there a simpler way to show and edit queries behind SQL view objects in databricks?

For example like in ssms where you can "Script View As", then change the create to an alter and change some things and run again to edit.

Upvotes: 2

Views: 4584

Answers (2)

BAllYouCanB
BAllYouCanB

Reputation: 23

@Karthikeyan's answer is correct, except that the last part of getting the view's SQL definition into your computer's clipboard is the trickiest. Here's how I've been doing it:

  • Right-click on the view which brings up a popup window with the columns >
  • Click the "Show query" button at the bottom right of that window to bring the view's SQL definition >
  • Left-click+drag your mouse from the start to the end of the SQL definition to select that text >
  • WITHOUT LETTING GO OF THE CLICKED MOUSE BUTTON, use your other hand to press Ctrl+C (or Cmd+C on a Mac), to copy the view definition to your clipboard

The popup window disappears when the mouse is released.

Upvotes: 1

We don't have direct option. But you can keep cursor on that result and get the formatted query and paste it another cell for editing .

enter image description here

Keep your cursor on :

enter image description here

You copy and paste it another cell for further edit : enter image description here

Upvotes: 0

Related Questions