Delete table
Tags: #snowflake #database #snippet
Author: Sanjay Sabu

Input

Import library

1
from snowflakeconnector import SnowflakeConnector
2
import snowflake.connector as snow
Copied!

Insert your credentials

1
username = "sanjaynaas"
2
password = "Password123"
Copied!

Specify your account details

1
account = "iz84541.europe-west4.gcp"
2
database = "DEMO_DB"
3
table_name = "NAAS_NEW"
4
warehouse_name = "COMPUTE_WH"
5
schema_name = "PUBLIC"
Copied!

Model

Connecting to Snowflake

1
conn = snow.connect(user=username,password=password,account=account)
2
cur = conn.cursor()
3
instance = SnowflakeConnector(username,password,account,database)
Copied!

Setting the environment

1
admin = "USE ROLE SYSADMIN"
2
cur.execute(admin)
3
warehouse_selection = "USE WAREHOUSE " + warehouse_name
4
cur.execute(warehouse_selection)
5
database_selection = "USE DATABASE " + database
6
cur.execute(database_selection)
7
schema_selection = "USE SCHEMA " + schema_name
8
cur.execute(schema_selection)
Copied!

To see existing tables

1
instance.execute_query("show tables",query_type="pull")
Copied!

Output

Table deletion

1
table_deletion = "DROP TABLE " + table_name
2
cur.execute(table_deletion)
Copied!

Table list after deletion

1
table_display_query = "SHOW TABLES"
2
#Fetch records from Snowflake database
3
instance.execute_query(table_display_query,query_type="pull")
Copied!

Display result

Copy link
Edit on GitHub