1. Query Primer Flashcards

(13 cards)

1
Q

create a new empty database with name “personaldb”

A

create database personaldb;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

specify the
database and schema in which you will be working

A

use schema personaldb.public;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Create a new table named “region” by copying all data from (table in another db) snowflakesampledata.tpch_sf1.region table.

A
CREATE TABLE region 
AS SELECT * FROM snowflake_sample_data.tpch_sf1.region;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Does creating new table by copying data from other table, also copies constraints or keys (i.e., primary keys, foreign keys, or indexes)

A

No

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Create a new (empty) table “region” or replace an existing one with the same name.

A

CREATE OR REPLACE TABLE PERSONALDB.PUBLIC.REGION

If a table named REGION already exists, it will be deleted and recreated with this new structure.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a common datatype used for IDs or keys of a table?

A

NUMBER(38,0)

This is a whole number column (no decimals), allowing up to 38 digits. Ideal for IDs or keys.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Snowflake SQL command to get current date

A

select current_date();

by default returns the
date in YYYY-MM-DD format

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Check what columns are available in the table “Region”.

A

describe table region;

result set shows: name, datatype, kind, null?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

get information about all tables available in the database personaldb

only 5 out of 18 possible columns

A

show terse tables in personaldb.public;

the output of show tables will only include tables that you’ve been given the privilege to see.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

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.

A

select ‘Welcome!’ as greeting,
5 * 3.14159 as circumference,
dayname(current_date()) as day_of_week;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

get the current date.

A

select current_date();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
  1. Alias the table snowflake_sample_data.tpch_sf1.supplier with s.
  2. Alias the column r_name with region_name.
A
  1. snowflake_sample_data.tpch_sf1.supplier s
  2. r_name as region_name
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Suppliers 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.

A
select * from suppliers s
inner join (select distinct ps_suppkey from partssupplied) ps
on s.suppkey = ps.suppkey;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly