Snowflake - Database



A database is a logical grouping of schemas where tables and columns resides. In this chapter, we will discuss about how to create a database, and view details.

Snowflake provides the user two ways to create a database, first way is by using user interface and the second way is by applying SQL query.

Working with Databases using Snowflake's UI

All data in Snowflake is maintained in databases. Each database consists of one or more schemas, which are logical groupings of database objects, such as tables and views. Snowflake does not restrict the limits on the number of databases, you can create schemas (within a database), or objects (within a schema).

Creating a Database

Login into Snowflake account using unique URL. Click Databases present at top ribbon as shown in the following screenshot −

Click Databases

It will navigate to the next screen. Click the Create button above the list of databases as shown below.

Click Create Button

It will take you to the Create Database dialog box. Enter the Database Name and Comment, then click the Finish button.

Click Create a Database

Once the database is created, user can view in the list as shown in the following screenshot −

Database List

View Warehouse

Now for viewing all the created databases, click Databases present at the top ribbon. It displays the View panel of the database where all the created databases are present.

Use the Create button for creating a new warehouse. User can clone a database as well, by selecting a database and clicking Clone as shown in the following screenshot −

Clone

It pops up a Clone Database dialog box to enter some information like Name, Source, Comment. After entering those details click Finish button as shown in the following screenshot −

Clone Database

User can see another database is created and it will be visible in view panel. User can also delete a database, by selecting a database and clicking on Drop button as shown in the following screenshot −

Deleting Database

It pops up a dialog box for confirmation. Click Yes for deletion, else No.

Drop Database Pop-Up

Working on Databases using Snowflake's SQL Interface

Here, we will learn how to create and view the databases by using the SQL interface of Snowflake.

Create Database

For creating a database, first you need to Login into Snowflake and navigate to Worksheets. By default, Worksheet is opened once the user logs in, else click the Worksheets icon present at the top ribbon.

Write the following query to create a database "TEST_DB_2"

CREATE DATABASE "TEST_DB_2" 

Now click the Run button to execute the query. Result will be displayed in the the Results panel as the TEST_DB_2 database was successfully created. The following screenshot displays the output processed by using SQL −

Create Database TEST_DB_2

View Databases

To view all the listed warehouses, user can use the following SQL. It brings the details of all listed warehouses.

SHOW DATABASES

To clone a database, user can use the following SQL, here “TEST_DB_3” is a new database named while DEMO_DB is used to clone it −

CREATE DATABASE TEST_DB_3 CLONE "DEMO_DB"

To delete database, use the following SQL −

DROP DATABASE "TEST_DB_3"

User can run SHOW DATABSE query after each operation to verify whether operation is completed.

Advertisements