I'm ending today with a clearer vision for my schema and entering the Snowflake landscape to build tables.

Tables I Plan on Building

I have 12 tables in mind. Two fact tables, one for Drug Application Information and one for Drug Submission Shortage information.

Drug Application Information will connect to Submission Information on Drug ID while Drug Shortage will connect to Discontinued Drugs on Drug ID.

Drug Application Information and Drug Shortage Information will both connect to Drug Information.

Which will then breakdown into Shortage Drug Information, Manufacturer Information, and Pharmaceutical Information.

Writing the Code in Snowfake

First I inputted the two base datasets, and I'm writing DQL in order to test the code before putting that into DML and DDL in order to create the tables.

For example, I tested this code in order to create manufacturer id:

SQL
with manufacturer_names as 
    (select
        manufacturer_name_flatten as manufacturer
    from 
        drug_application_information
    union
    
    select
        manufacturer_name
    from
        drug_shortage_information)
select
    row_number() over (order by manufacturer) as manufacturer_id,
    manufacturer
from
    manufacturer_names
where
    manufacturer is not null;

This is a CTE for creating the id based on row number after a union of the manufacturer names from both of the base tables. Then, I used this code to create the table and then insert the values:

SQL
//create manufacturer_information 
create or replace table manufacturer_information(
    manufacturer_id int primary key,
    manufacturer_name varchar(100)
);

//insert data into manufacturer_information
insert into 
    manufacturer_information

   with manufacturer_names as 
        (select
            manufacturer_name_flatten as manufacturer
        from 
            drug_application_information
        union
        
        select
            manufacturer_name
        from
            drug_shortage_information)
select
    row_number() over (order by manufacturer) as manufacturer_id,
    manufacturer
from 
    manufacturer_names
where
    manufacturer is not null;

In this code I'm creating the table with the relevant constraints. For example, by adding "primary key" after manufacturer_id, any duplicates values would cause an error. Then, I took my earlier CTE, changed it a little, and used it to insert values from the base tables.

Next Steps

I plan on repeating these steps for all of my tables. Then, I can connect Snowflake to Tableau and begin designing and building my dashboards.