Built with Tutify.io

    AIStudyLabs

    Snowflake Create, Clone, Drop Database

    Snowflake Create, Clone, Drop Database

    In this section, you will learn Snowflake DDL database commands which include creating a database, cloning database, dropping database and more. You can run all these commands either from Snowflake web console or from your local machine using SnowSQL CLI.

    <a id="h-create-a-snowflake-database"></a>

    Create a Snowflake Database

    Using CREATE DABATAE you can create a Snowflake database.

    
    CREATE DATABASE EMPLOYEE;
    CREATE DATABASE EMPLOYEE DATA_RETENTION_TIME_IN_DAYS 5;
    

    <a id="h-create-or-replace-database"></a>

    Create or Replace Database

    Use OR REPLACE in order to drop the existing Snowflake database and create a new database. You can also do this first by running DROP DATABASE and running CREATE DATABASE

    
    CREATE OR REPLACE DATABASE EMPLOYEE;
    

    <a id="h-create-a-transient-database"></a>

    Create a Transient database

    Use TRASIENT option to create a trasient database. transient databases are not fail-safe and take less storage hence, there is no recovery when data loss.

    
    CREATE TRANSIENT DATABASE EMPLOYEE;
    

    <a id="h-clone-database"></a>

    Clone Database

    use optional CLONE optional parameter in order to clone the existing database, Cloning database copies all schema, tables and everything from the database.

    
    CREATE DATABASE EMPLOYEE_CLONE CLONE EMPLOYEE ;
    +-----------------------------------------------+
    | status                                        |
    |-----------------------------------------------|
    | Database EMPLOYEE_CLONE successfully created. |
    +-----------------------------------------------+
    1 Row(s) produced. Time Elapsed: 2.644s
    

    <a id="h-drop-database"></a>

    Drop Database

    DROP DATABSE is used to drop the existing snowflake database

    
    DROP DATABASE EMPLOYEE;
    +--------------------------------+
    | status                         |
    |--------------------------------|
    | EMPLOYEE successfully dropped. |
    +--------------------------------+
    1 Row(s) produced. Time Elapsed: 0.132s
    

    <a id="h-show-database"></a>

    Show Database

    Using SHOW DATABSE, you can see all the tables in the Snowflake account.

    
    SHOW DATABASES;
    +-------------------------------+-----------------------+------------+------------+-------------------------+--------------+----------------------------+---------+----------------+
    | created_on                    | name                  | is_default | is_current | origin                  | owner        | comment                    | options | retention_time |
    |-------------------------------+-----------------------+------------+------------+-------------------------+--------------+----------------------------+---------+----------------|
    | 2020-02-23 17:13:40.755 -0800 | DEMO_DB               | N          | N          |                         | SYSADMIN     | demo database              |         | 1              |
    | 2020-03-07 19:25:04.549 -0800 | EMPLOYEE_CLONE        | N          | Y          |                         | SYSADMIN     |                            |         | 1              |
    | 2020-02-23 17:13:41.635 -0800 | SNOWFLAKE_SAMPLE_DATA | N          | N          | SFC_SAMPLES.SAMPLE_DATA | ACCOUNTADMIN | TPC-H, OpenWeatherMap, etc |         | 1              |
    | 2020-02-23 17:13:35.624 -0800 | UTIL_DB               | N          | N          |                         | SYSADMIN     | utility database           |         | 1              |
    +-------------------------------+-----------------------+------------+------------+-------------------------+--------------+----------------------------+---------+----------------+
    4 Row(s) produced. Time Elapsed: 0.142s
    

    It also shows all default databases that come with account creation.

    <a id="h-set-default-database"></a>

    Set default Database

    If you wanted to set the default database.

    
    USE employee_clone
    

    <a id="h-related-articles"></a>

    Related Articles

    <a id="h-references"></a>

    References