create a new empty database with name “personaldb”
create database personaldb;
specify the
database and schema in which you will be working
use schema personaldb.public;
Create a new table named “region” by copying all data from (table in another db) snowflakesampledata.tpch_sf1.region table.
CREATE TABLE region AS SELECT * FROM snowflake_sample_data.tpch_sf1.region;
Does creating new table by copying data from other table, also copies constraints or keys (i.e., primary keys, foreign keys, or indexes)
No
Create a new (empty) table “region” or replace an existing one with the same name.
CREATE OR REPLACE TABLE PERSONALDB.PUBLIC.REGION
If a table named REGION already exists, it will be deleted and recreated with this new structure.
What is a common datatype used for IDs or keys of a table?
NUMBER(38,0)
This is a whole number column (no decimals), allowing up to 38 digits. Ideal for IDs or keys.
Snowflake SQL command to get current date
select current_date();
by default returns the
date in YYYY-MM-DD format
Check what columns are available in the table “Region”.
describe table region;
result set shows: name, datatype, kind, null?
get information about all tables available in the database personaldb
only 5 out of 18 possible columns
show terse tables in personaldb.public;
the output of show tables will only include tables that you’ve been given the privilege to see.
Write snowflake sql query to show “Welcome!” in first column, 5*PI value as circumference in second column, name of current day in third column.
select ‘Welcome!’ as greeting,
5 * 3.14159 as circumference,
dayname(current_date()) as day_of_week;
get the current date.
select current_date();
snowflake_sample_data.tpch_sf1.supplier with s.r_name with region_name.snowflake_sample_data.tpch_sf1.supplier sr_name as region_nameSuppliers and PartsSupplied are two tables, with PKs as s_suppkey and ps_partkey respectively. ps_suppkey acts as foreign key in PartsSupplied table.
Write a Query to get suppliers who have supplied at least once.
select * from suppliers s inner join (select distinct ps_suppkey from partssupplied) ps on s.suppkey = ps.suppkey;