Are you looking for details about commonly used commands in Snowflake? Are you also interested in knowing what are DML, DDL snowflake commands? Then you have reached the right place. In this article, we will explore more about snowflake commands.
A) Types of commands in Snowflake
There are four types of commands present in snowflake and those are
1. DDL - Data Definition Language
2. DML - Data Manipulation Language
3. DCL - Data Control Language
4. TCL - Transaction Control Language
In this article, we will focus on DDL and DML commands use in Snowflake
B) What commonly used DDL commands in Snowflake?
Here is the list of DDL commands used in snowflake
Let's see each of these commands one by one -
1. AFTER - AFTER command is used to modify metadata of on account level, parameters for session or metadata of the database object
AFTER <object_type> <object_name> <actions>
e.g AFTER SESSION SET < params >
2. CREATE - CREATE command is used to create new object
CREATE <object_type> <object_name>
e.g. CREATE DATABASE ABC
3. DROP - DROP command is used for removing object from system.
Syntax : DROP <object_type> [IF EXISTS] <identifier>
e.g DROP USER [IF EXISTS] abc_ user
4. USE - USE command is used to specify role, warehouse database ,or schema for current session
Syntax : USE WAREHOUSE <name>
e.g USE WAREHOUSE xyz
5. SHOW - SHOW command is used to provide metadata for the object.
Syntax : SHOW <object_ type_plural> [LIKE '<pattern>']
e.g SHOW PARAMETERS [LIKE '<pattern>']
C) What are commonly used DML commands in Snowflake?
Here is the list of DDL commands used in Snowflake
Let's see each of these commands one by one.
1. INSERT - INSERT command is used to insert one or more rows into the table.
INSERT INTO <table_name> [< column_name>]
INSERT INTO TAB_ABC (id, name)
VALUES ( 100 , ' DRONA')
2) MERGE - MERGE command is used to Insert, delete and update values in a table based on values in a subquery or another table.
MERGE INTO <table_name> USING <source> ON <join_exp>L
MERGE INTO TAB_ABC USING TAB_PQR ON TAB_ABC.ID=TAB_PQR.ID WHEN MATCHED Then
Update set TAB_ABC .NAME = TAB_PQR.NAME
3. UPDATE: The UPDATE command is used to update rows in the table.
UPDATE <table_name> SET <field>=<value>
UPDATE TAB_ABC SET NAME = 'XYZ'
4. DELETE : DELETE command is used to delete records from the table.
DELETE FROM <table_name > WHERE <condition>
DELETE FROM TAB_ABC WHERE NAME='BOB'
5) TRUNCATE: TRUNCATE command is used to remove records from the table including privileges and constraints.
TRUNCATE TABLE <table _name>
TRUNCATE TABLE TAB_ ABC.