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.
- Implement the Requirement using Javascript Procedure:
Execute the procedure and this will insert data into table:
SELECT * FROM DDL_INFO;
Proc Output:
- Implement the Requirement using SQL Scripting Procedure:
Execute the Procedure and observe the output:
- Implement the Requirement using 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: