Clock Slave
Clock Slave

Reputation: 7977

Get query used to create a table

We use snowflake at work to store data, and for one of the tables, I dont have the SQL query used to create the table. Is there a way to see the query used to make that table?

I tried using the following

get_ddl('table', 'db.table', true)

but this gives me an output like-

enter image description here

This doesnt give me any information about the sql query that was used. How do I get that in snowflake?

Upvotes: 0

Views: 1232

Answers (1)

Marcel
Marcel

Reputation: 2622

If get_ddl() is not enough you may use INFORMATION_SCHEMA. To get more information you have 2 options:

  1. Use the QUERY_HISTORY() table functions: https://docs.snowflake.com/en/sql-reference/functions/query_history.html
  2. Use the QUERY_HISTORY() view: https://docs.snowflake.com/en/sql-reference/account-usage/query_history.html

If you use the funtions/view above and filter all the records by QUERY_TEXT, maybe you get more information about the exact SQL that was used to create your table.

Upvotes: 2

Related Questions