Step 2. Create Snowflake Objects¶
In this step, you create the following Snowflake objects:
A database (
sf_tuts
) and a table (emp_basic
). You load sample data into this table.A virtual warehouse (
sf_tuts_wh
). This warehouse provides the compute resources needed to load data into the table and query the table. For this tutorial, you create an X-Small warehouse.
At the end of this tutorial, you will remove these objects.
Creating a Database¶
Create the sf_tuts
database using the CREATE DATABASE command:
CREATE OR REPLACE DATABASE sf_tuts;
In this tutorial, you use the default schema (public
) available
for each database, rather than creating a new schema.
Note that the database and schema you just created are now in use for your current session, as reflected in the SnowSQL command prompt. You can also use the context functions to get this information.
SELECT CURRENT_DATABASE(), CURRENT_SCHEMA();
The following is an example result:
+--------------------+------------------+ | CURRENT_DATABASE() | CURRENT_SCHEMA() | |--------------------+------------------| | SF_TUTS | PUBLIC | +--------------------+------------------+
Creating a Table¶
Create a table named emp_basic
in sf_tuts.public
using the CREATE TABLE command:
CREATE OR REPLACE TABLE emp_basic ( first_name STRING , last_name STRING , email STRING , streetaddress STRING , city STRING , start_date DATE );
Note that the number of columns in the table, their positions, and their data types correspond to the fields in the sample CSV data files that you will be staging in the next step in this tutorial.
Creating a Virtual Warehouse¶
Create an X-Small warehouse named sf_tuts_wh
using the CREATE WAREHOUSE command:
CREATE OR REPLACE WAREHOUSE sf_tuts_wh WITH WAREHOUSE_SIZE='X-SMALL' AUTO_SUSPEND = 180 AUTO_RESUME = TRUE INITIALLY_SUSPENDED=TRUE;
The sf_tuts
warehouse is initially suspended but the DML statement also sets
AUTO_RESUME = true
. The AUTO_RESUME setting causes a warehouse to automatically start
when SQL statements that require compute resources are executed.
Also, note that the warehouse is now in use for your current session. This information is displayed in your SnowSQL command prompt. You can also display the name of the warehouse by using the following context function:
SELECT CURRENT_WAREHOUSE();
The following is an example result:
+---------------------+ | CURRENT_WAREHOUSE() | |---------------------| | SF_TUTS_WH | +---------------------+