1 0
Read Time:1 Minute, 35 Second

During this post we will discuss the multiple ways to extract the DDL from your snowflake database. Though we can use GET_DDL command to extract the metadata. But what if our database has huge list of tables and running GET_DDL on each table is not feasible approach. There should be some programmatic approach which should traverse the Table list automatically and extract the DDL. Later on we can refer this DDL and migrate them to any other environment or Database wo create the tables without much manual intervention.

To implement the same, I have used below three approaches to extract the DDL from Database.

Lets see the technical implementation:

We will be extracting the DDL from source DB i.e. DEMO_DB. As per the below screenshot we could see there are 50 tables present in DB.

Tables List
  • Implement the Requirement using Javascript Procedure:
GET_DDL_JS

Execute the procedure and this will insert data into table:

SELECT * FROM DDL_INFO;

DDL_INFO

Proc Output:

JS Proc Output
  • Implement the Requirement using SQL Scripting Procedure:
SQL_SCRIPT_PROC

Execute the Procedure and observe the output:

SQL_PROC_OUTPUT
  • Implement the Requirement using Python Procedure:
Python Procedure

get_ddl_object: preapre the sql statement like

SELECT GET_DDL(‘TABLE’,'<<TABLENAME>>)

Output generated in below way:

After execution of the Python code, Output File gets created in directory:

Python Proc Output

Average Rating

5 Star
0%
4 Star
0%
3 Star
0%
2 Star
0%
1 Star
0%

Leave a Reply

Your email address will not be published. Required fields are marked *