Foodmart
consists of an application capable of managing sales, costs and profits yearly and monthly.
Moreover, Foodmart
comprises different tables that allow the user to file transaction information about products, customers, stores, warehouses, promotions and employees.
Moving through these fields allows to configure different setups to display useful boards or graphics.
1 Data model
The following sections will follow the displayed data model in order to create the application and its transaction forms, graphs and lists.
To represent the sales invoices we will have a main table sales_fact
from which other tables such as the sales_fact_month_customer
, sales_fact_month_product
, sales_fact_month_store
and
sales_fact_yearmonth_customer
, sales_fact_yearmonth_product
, sales_fact_yearmonth_store
will grab the needed data to compute monthly and yearly sales, costs, profit among other values.
This tables can be found in more detail in the product
, customer
and store
sections.
This is the structure the sales invoices tables follow:
This design allows the user to only transaction with one big table and obtain personalized results automatically without transactioning with the other related tables.
As of now only sales_fact_month
and sales_fact_yearmonth
are implemented. The other parts of the pyramid could be developed in the future. More detailed information about how the tables are filled can be found in the triggers and procedures sections.
2 Tables
Following the previous data model, the table definitions and their column meanings will be explained briefly below.
2.1 Time
The table time_by_day
gives a time and date an identification number in order to avoid extra information on invoice entries.
-- ************************************************************************** -- DEISTER WebStudio XSQL-SCHEMA Fri Jun 21 16:28:33 CEST 2019 Engine: informix -- time_by_day -- ************************************************************************** CREATE TABLE time_by_day ( time_id serial not null, the_date date default current not null, the_datetime datetime year to second not null, the_day varchar(30), the_month varchar(30), the_year smallint, day_of_month smallint, week_of_year integer, month_of_year smallint, quarter varchar(30), fiscal_period varchar(30) ); ALTER TABLE time_by_day LOCK MODE (ROW); CREATE INDEX i_time_by_day1 ON time_by_day(the_date); CREATE INDEX i_time_by_day2 ON time_by_day(the_year); -- Index to avoid automatic named by database (named with pk name). CREATE UNIQUE INDEX p_time_by_day ON time_by_day(time_id); ALTER TABLE time_by_day ADD CONSTRAINT PRIMARY KEY (time_id) CONSTRAINT p_time_by_day;
-- ************************************************************************** -- DEISTER WebStudio XSQL-SCHEMA Fri Jun 21 16:28:48 CEST 2019 Engine: postgres -- time_by_day -- ************************************************************************** CREATE TABLE time_by_day ( time_id serial not null, the_date date default current not null, the_datetime timestamp not null, the_day varchar(30), the_month varchar(30), the_year smallint, day_of_month smallint, week_of_year integer, month_of_year smallint, quarter varchar(30), fiscal_period varchar(30) ) WITH OIDS; CREATE INDEX i_time_by_day1 ON time_by_day(the_date); CREATE INDEX i_time_by_day2 ON time_by_day(the_year); -- Database Server on Postgres, DB2 will be created a index automatically with the same name of pk ALTER TABLE time_by_day ADD CONSTRAINT p_time_by_day PRIMARY KEY (time_id);
Column | Type | Details | Definition |
---|---|---|---|
time_id | serial | Primary key. | Time identifier. |
the_date | date | Date. | |
the_datetime | datetime | Date and time. | |
the_day | varchar | Name of the day. | |
the_month | varchar | Name of the month. | |
the_year | smallint | Year. | |
day_of_month | smallint | Numerical day. | |
week_of_year | integer | Week number. | |
month_of_year | smallint | Numerical month. | |
quarter | varchar | Year quarter. | |
fiscal_period | varchar | Fiscal period. |
2.2 Sale's Invoices
The table sales_fact
gives time based invoices about sales, costs and units for each product
bought at a store
by a customer
at a certain time and date.
-- ************************************************************************** -- DEISTER WebStudio XSQL-SCHEMA Fri Jun 21 16:11:27 CEST 2019 Engine: informix -- sales_fact -- ************************************************************************** CREATE TABLE sales_fact ( product_id integer not null, time_id integer not null, customer_id integer not null, promotion_id integer not null, store_id integer not null, store_sales decimal(10,4) not null, store_cost decimal(10,4) not null, unit_sales decimal(10,4) not null ); ALTER TABLE sales_fact LOCK MODE (ROW); CREATE INDEX i_sales_fact1 ON sales_fact(time_id); CREATE INDEX i_sales_fact2 ON sales_fact(customer_id); CREATE INDEX i_sales_fact3 ON sales_fact(store_id); CREATE INDEX i_sales_fact4 ON sales_fact(product_id); -- Omitido indice f_sales_fact dado que ya existe un indice sobre las columnas ALTER TABLE sales_fact ADD CONSTRAINT FOREIGN KEY (time_id) REFERENCES time_by_day(time_id) CONSTRAINT f_sales_fact; -- Omitido indice f_sales_fact2 dado que ya existe un indice sobre las columnas ALTER TABLE sales_fact ADD CONSTRAINT FOREIGN KEY (customer_id) REFERENCES customer(customer_id) CONSTRAINT f_sales_fact2; -- Omitido indice f_sales_fact3 dado que ya existe un indice sobre las columnas ALTER TABLE sales_fact ADD CONSTRAINT FOREIGN KEY (product_id) REFERENCES product(product_id) CONSTRAINT f_sales_fact3; -- Omitido indice f_sales_fact4 dado que ya existe un indice sobre las columnas ALTER TABLE sales_fact ADD CONSTRAINT FOREIGN KEY (store_id) REFERENCES store(store_id) CONSTRAINT f_sales_fact4;
-- ************************************************************************** -- DEISTER WebStudio XSQL-SCHEMA Fri Jun 21 16:11:33 CEST 2019 Engine: postgres -- sales_fact -- ************************************************************************** CREATE TABLE sales_fact ( product_id integer not null, time_id integer not null, customer_id integer not null, promotion_id integer not null, store_id integer not null, store_sales decimal(10,4) not null, store_cost decimal(10,4) not null, unit_sales decimal(10,4) not null ) WITH OIDS; CREATE INDEX i_sales_fact1 ON sales_fact(time_id); CREATE INDEX i_sales_fact2 ON sales_fact(customer_id); CREATE INDEX i_sales_fact3 ON sales_fact(store_id); CREATE INDEX i_sales_fact4 ON sales_fact(product_id); -- Omitido indice f_sales_fact dado que ya existe un indice sobre las columnas ALTER TABLE sales_fact ADD CONSTRAINT f_sales_fact FOREIGN KEY (time_id) REFERENCES time_by_day(time_id) DEFERRABLE INITIALLY IMMEDIATE ; -- Omitido indice f_sales_fact2 dado que ya existe un indice sobre las columnas ALTER TABLE sales_fact ADD CONSTRAINT f_sales_fact2 FOREIGN KEY (customer_id) REFERENCES customer(customer_id) DEFERRABLE INITIALLY IMMEDIATE ; -- Omitido indice f_sales_fact3 dado que ya existe un indice sobre las columnas ALTER TABLE sales_fact ADD CONSTRAINT f_sales_fact3 FOREIGN KEY (product_id) REFERENCES product(product_id) DEFERRABLE INITIALLY IMMEDIATE ; -- Omitido indice f_sales_fact4 dado que ya existe un indice sobre las columnas ALTER TABLE sales_fact ADD CONSTRAINT f_sales_fact4 FOREIGN KEY (store_id) REFERENCES store(store_id) DEFERRABLE INITIALLY IMMEDIATE ;
Column | Type | Details | Definition |
---|---|---|---|
product_id | integer |
Primary key.
References to product .product_id.
|
Product identifier. |
time_id | integer |
Primary key.
References to time_by_day .time_id.
|
Time identifier. |
customer_id | integer |
Primary key.
References to customer .customer_id.
|
Customer identifier. |
promotion_id | integer |
References to promotion .promotion_id.
|
Promotion identifier. |
store_id | serial |
Primary key.
References to store .store_id.
|
Store identifier. |
store_sales | decimal | Sales. | |
store_cost | decimal | Cost. | |
unit_sales | decimal | Units sold. |
This table provides data through procedure based triggers to sales_fact_month_customer
, sales_fact_yearmonth_customer
, sales_fact_month_store
, sales_fact_yearmonth_store
,
sales_fact_month_product
, sales_fact_yearmonth_product
. This tables will be discussed in the following sections dedicated to each of the parts.
2.3 Product
In this section all the tables associated with product
will be placed here.
-- ************************************************************************** -- DEISTER WebStudio XSQL-SCHEMA Mon Jul 01 10:23:55 CEST 2019 Engine: informix -- promotion -- ************************************************************************** CREATE TABLE promotion ( promotion_id integer not null, promotion_district_id integer, promotion_name varchar(30), media_type varchar(30), cost decimal(10,4), start_date datetime year to second, end_date datetime year to second ); ALTER TABLE promotion LOCK MODE (ROW); -- Index to avoid automatic named by database (named with pk name). CREATE UNIQUE INDEX p_promotion ON promotion(promotion_id); ALTER TABLE promotion ADD CONSTRAINT PRIMARY KEY (promotion_id) CONSTRAINT p_promotion;-- ************************************************************************** -- DEISTER WebStudio XSQL-SCHEMA Fri Jun 21 11:53:08 CEST 2019 Engine: informix -- product_class -- ************************************************************************** CREATE TABLE product_class ( product_class_id integer not null, product_category varchar(30), product_subcategory varchar(30), product_department varchar(30), product_family varchar(30) ); ALTER TABLE product_class LOCK MODE (ROW); -- Index to avoid automatic named by database (named with pk name). CREATE UNIQUE INDEX p_product_class ON product_class(product_class_id); ALTER TABLE product_class ADD CONSTRAINT PRIMARY KEY (product_class_id) CONSTRAINT p_product_class; -- ************************************************************************** -- DEISTER WebStudio XSQL-SCHEMA Fri Jun 21 11:54:48 CEST 2019 Engine: informix -- product -- ************************************************************************** CREATE TABLE product ( product_id integer not null, product_name varchar(60) not null, product_class_id integer not null, brand_name varchar(60), sku decimal(17,0) not null, srp decimal(10,4), gross_weight decimal(17,0), net_weight decimal(17,0), recyclable_package boolean, low_fat boolean, units_per_case smallint, cases_per_pallet smallint, shelf_width decimal(17,0), shelf_height decimal(17,0), shelf_depth decimal(17,0) ); ALTER TABLE product LOCK MODE (ROW); -- Index to avoid automatic named by database (named with pk name). CREATE UNIQUE INDEX p_product ON product(product_id); ALTER TABLE product ADD CONSTRAINT PRIMARY KEY (product_id) CONSTRAINT p_product; CREATE INDEX f_product ON product(product_class_id); ALTER TABLE product ADD CONSTRAINT FOREIGN KEY (product_class_id) REFERENCES product_class(product_class_id) CONSTRAINT f_product; -- ************************************************************************** -- DEISTER WebStudio XSQL-SCHEMA Fri Jun 21 11:55:57 CEST 2019 Engine: informix -- sales_fact_month_product -- ************************************************************************** CREATE TABLE sales_fact_month_product ( product_id integer not null, the_year integer not null, unit_sales integer default 0, unit_sales_prev integer default 0, sales decimal(10,4) default 0.0, sales_prev decimal(10,4) default 0.0, sales_pct decimal(10,4) default 0.0, sales_avg decimal(10,4) default 0.0, sales_jan decimal(10,4) default 0.0, sales_feb decimal(10,4) default 0.0, sales_mar decimal(10,4) default 0.0, sales_apr decimal(10,4) default 0.0, sales_may decimal(10,4) default 0.0, sales_jun decimal(10,4) default 0.0, sales_jul decimal(10,4) default 0.0, sales_ago decimal(10,4) default 0.0, sales_sep decimal(10,4) default 0.0, sales_oct decimal(10,4) default 0.0, sales_nov decimal(10,4) default 0.0, sales_dec decimal(10,4) default 0.0, cost decimal(10,4) default 0.0, cost_jan decimal(10,4) default 0.0, cost_feb decimal(10,4) default 0.0, cost_mar decimal(10,4) default 0.0, cost_apr decimal(10,4) default 0.0, cost_may decimal(10,4) default 0.0, cost_jun decimal(10,4) default 0.0, cost_jul decimal(10,4) default 0.0, cost_ago decimal(10,4) default 0.0, cost_sep decimal(10,4) default 0.0, cost_oct decimal(10,4) default 0.0, cost_nov decimal(10,4) default 0.0, cost_dec decimal(10,4) default 0.0, cost_prev decimal(10,4) default 0.0, cost_pct decimal(10,4) default 0.0, cost_avg decimal(10,4) default 0.0, profit decimal(10,4) default 0.0, promotion_sales decimal(10,4) default 0.0, promotion_sales_prev decimal(10,4) default 0.0, sales_count integer default 0, sales_count_prev integer default 0 ); ALTER TABLE sales_fact_month_product LOCK MODE (ROW); -- Index to avoid automatic named by database (named with pk name). CREATE UNIQUE INDEX p_sales_fact_month_product ON sales_fact_month_product(product_id, the_year); ALTER TABLE sales_fact_month_product ADD CONSTRAINT PRIMARY KEY (product_id, the_year) CONSTRAINT p_sales_fact_month_product; CREATE INDEX f_sales_fact_month_product ON sales_fact_month_product(product_id); ALTER TABLE sales_fact_month_product ADD CONSTRAINT FOREIGN KEY (product_id) REFERENCES product(product_id) CONSTRAINT f_sales_fact_month_product; -- ************************************************************************** -- DEISTER WebStudio XSQL-SCHEMA Fri Jun 21 11:56:33 CEST 2019 Engine: informix -- sales_fact_yearmonth_product -- ************************************************************************** CREATE TABLE sales_fact_yearmonth_product ( product_id integer not null, the_year integer not null, the_month varchar(30) not null, month_of_year integer not null, unit_sales integer default 0, unit_sales_prev integer default 0, sales decimal(10,4) default 0.0, sales_prev decimal(10,4) default 0.0, sales_pct decimal(10,4) default 0.0, sales_avg decimal(10,4) default 0.0, cost decimal(10,4) default 0.0, cost_prev decimal(10,4) default 0.0, cost_pct decimal(10,4) default 0.0, cost_avg decimal(10,4) default 0.0, profit decimal(10,4) default 0.0, promotion_sales decimal(10,4) default 0.0, promotion_sales_prev decimal(10,4) default 0.0, sales_count integer default 0, sales_count_prev integer default 0 ); ALTER TABLE sales_fact_yearmonth_product LOCK MODE (ROW); -- Index to avoid automatic named by database (named with pk name). CREATE UNIQUE INDEX p_sales_fact_yearmonth_product ON sales_fact_yearmonth_product(product_id, the_year, month_of_year); ALTER TABLE sales_fact_yearmonth_product ADD CONSTRAINT PRIMARY KEY (product_id, the_year, month_of_year) CONSTRAINT p_sales_fact_yearmonth_product; CREATE INDEX f_sales_fact_yearmonth_product ON sales_fact_yearmonth_product(product_id); ALTER TABLE sales_fact_yearmonth_product ADD CONSTRAINT FOREIGN KEY (product_id) REFERENCES product(product_id) CONSTRAINT f_sales_fact_yearmonth_product;
-- ************************************************************************** -- DEISTER WebStudio XSQL-SCHEMA Mon Jul 01 10:24:10 CEST 2019 Engine: postgres -- promotion -- ************************************************************************** CREATE TABLE promotion ( promotion_id integer not null, promotion_district_id integer, promotion_name varchar(30), media_type varchar(30), cost decimal(10,4), start_date timestamp, end_date timestamp ) WITH OIDS; -- Database Server on Postgres, DB2 will be created a index automatically with the same name of pk ALTER TABLE promotion ADD CONSTRAINT p_promotion PRIMARY KEY (promotion_id); -- ************************************************************************** -- DEISTER WebStudio XSQL-SCHEMA Fri Jun 21 11:53:52 CEST 2019 Engine: postgres -- product_class -- ************************************************************************** CREATE TABLE product_class ( product_class_id integer not null, product_category varchar(30), product_subcategory varchar(30), product_department varchar(30), product_family varchar(30) ) WITH OIDS; -- Database Server on Postgres, DB2 will be created a index automatically with the same name of pk ALTER TABLE product_class ADD CONSTRAINT p_product_class PRIMARY KEY (product_class_id); -- ************************************************************************** -- DEISTER WebStudio XSQL-SCHEMA Fri Jun 21 11:55:03 CEST 2019 Engine: postgres -- product -- ************************************************************************** CREATE TABLE product ( product_id integer not null, product_name varchar(60) not null, product_class_id integer not null, brand_name varchar(60), sku decimal(17,0) not null, srp decimal(10,4), gross_weight decimal(17,0), net_weight decimal(17,0), recyclable_package boolean, low_fat boolean, units_per_case smallint, cases_per_pallet smallint, shelf_width decimal(17,0), shelf_height decimal(17,0), shelf_depth decimal(17,0) ) WITH OIDS; -- Database Server on Postgres, DB2 will be created a index automatically with the same name of pk ALTER TABLE product ADD CONSTRAINT p_product PRIMARY KEY (product_id); CREATE INDEX f_product ON product(product_class_id); ALTER TABLE product ADD CONSTRAINT f_product FOREIGN KEY (product_class_id) REFERENCES product_class(product_class_id) DEFERRABLE INITIALLY IMMEDIATE ; -- ************************************************************************** -- DEISTER WebStudio XSQL-SCHEMA Fri Jun 21 11:56:16 CEST 2019 Engine: postgres -- sales_fact_month_product -- ************************************************************************** CREATE TABLE sales_fact_month_product ( product_id integer not null, the_year integer not null, unit_sales integer default 0, unit_sales_prev integer default 0, sales decimal(10,4) default 0.0, sales_prev decimal(10,4) default 0.0, sales_pct decimal(10,4) default 0.0, sales_avg decimal(10,4) default 0.0, sales_jan decimal(10,4) default 0.0, sales_feb decimal(10,4) default 0.0, sales_mar decimal(10,4) default 0.0, sales_apr decimal(10,4) default 0.0, sales_may decimal(10,4) default 0.0, sales_jun decimal(10,4) default 0.0, sales_jul decimal(10,4) default 0.0, sales_ago decimal(10,4) default 0.0, sales_sep decimal(10,4) default 0.0, sales_oct decimal(10,4) default 0.0, sales_nov decimal(10,4) default 0.0, sales_dec decimal(10,4) default 0.0, cost decimal(10,4) default 0.0, cost_jan decimal(10,4) default 0.0, cost_feb decimal(10,4) default 0.0, cost_mar decimal(10,4) default 0.0, cost_apr decimal(10,4) default 0.0, cost_may decimal(10,4) default 0.0, cost_jun decimal(10,4) default 0.0, cost_jul decimal(10,4) default 0.0, cost_ago decimal(10,4) default 0.0, cost_sep decimal(10,4) default 0.0, cost_oct decimal(10,4) default 0.0, cost_nov decimal(10,4) default 0.0, cost_dec decimal(10,4) default 0.0, cost_prev decimal(10,4) default 0.0, cost_pct decimal(10,4) default 0.0, cost_avg decimal(10,4) default 0.0, profit decimal(10,4) default 0.0, promotion_sales decimal(10,4) default 0.0, promotion_sales_prev decimal(10,4) default 0.0, sales_count integer default 0, sales_count_prev integer default 0 ) WITH OIDS; -- Database Server on Postgres, DB2 will be created a index automatically with the same name of pk ALTER TABLE sales_fact_month_product ADD CONSTRAINT p_sales_fact_month_product PRIMARY KEY (product_id, the_year); CREATE INDEX f_sales_fact_month_product ON sales_fact_month_product(product_id); ALTER TABLE sales_fact_month_product ADD CONSTRAINT f_sales_fact_month_product FOREIGN KEY (product_id) REFERENCES product(product_id) DEFERRABLE INITIALLY IMMEDIATE ; -- ************************************************************************** -- DEISTER WebStudio XSQL-SCHEMA Fri Jun 21 11:56:45 CEST 2019 Engine: postgres -- sales_fact_yearmonth_product -- ************************************************************************** CREATE TABLE sales_fact_yearmonth_product ( product_id integer not null, the_year integer not null, the_month varchar(30) not null, month_of_year integer not null, unit_sales integer default 0, unit_sales_prev integer default 0, sales decimal(10,4) default 0.0, sales_prev decimal(10,4) default 0.0, sales_pct decimal(10,4) default 0.0, sales_avg decimal(10,4) default 0.0, cost decimal(10,4) default 0.0, cost_prev decimal(10,4) default 0.0, cost_pct decimal(10,4) default 0.0, cost_avg decimal(10,4) default 0.0, profit decimal(10,4) default 0.0, promotion_sales decimal(10,4) default 0.0, promotion_sales_prev decimal(10,4) default 0.0, sales_count integer default 0, sales_count_prev integer default 0 ) WITH OIDS; -- Database Server on Postgres, DB2 will be created a index automatically with the same name of pk ALTER TABLE sales_fact_yearmonth_product ADD CONSTRAINT p_sales_fact_yearmonth_product PRIMARY KEY (product_id, the_year, month_of_year); CREATE INDEX f_sales_fact_yearmonth_product ON sales_fact_yearmonth_product(product_id); ALTER TABLE sales_fact_yearmonth_product ADD CONSTRAINT f_sales_fact_yearmonth_product FOREIGN KEY (product_id) REFERENCES product(product_id) DEFERRABLE INITIALLY IMMEDIATE ;
Column | Type | Details | Definition |
---|---|---|---|
promotion_id | integer | Primary key. | Promotion identifier. |
promotion_district_id | integer |
References to district .district_id.
|
District identifier. |
promotion_name | varchar | Promotion name. | |
media_type | varchar | Promotion media type. | |
cost | decimal | Promotion cost. | |
start_date | datetime | Promotion start date. | |
end_date | datetime | Promotion end date. |
promotion
provides information about the possible promotions to be applied to products.
Column | Type | Details | Definition |
---|---|---|---|
product_class_id | integer | Primary key. | Product class identifier. |
product_category | varchar | Product category. | |
product_subcategory | varchar | Product subcategory. | |
product_department | varchar | Product department . |
|
product_family | varchar | Product family. |
product_class
stores all the different categories and subcategories a product
can be part of.
Column | Type | Details | Definition |
---|---|---|---|
product_id | integer | Primary key. | Product identifier. |
product_name | varchar | Product name. | |
product_class_id | integer | References product_class .product_class_id. |
Product class identifier. |
brand_name | varchar | Product's brand name. | |
sku | decimal | Product's amount of stock keeping units (SKU). | |
srp | decimal | Product's amount of shelf ready packaging (SRP). | |
gross_weight | decimal | Product's gross weight. | |
net_weight | decimal | Product's net weight. | |
recyclable_packaging | boolean | Whether product 's packaging is recyclable or not. |
|
low_fat | boolean | Whether product 's low fat or not. |
|
units_per_case | smallint | Product's units per case. | |
cases_per_pallet | smallint | Product's cases per pallet. | |
shelf_width | decimal | Product's shelf width. | |
shelf_height | decimal | Product's shelf height. | |
shelf_depth | decimal | Product's shelf depth. |
product
provides information about products and relates to product_class
by its id.
Column | Type | Details | Definition |
---|---|---|---|
product_id | integer |
Primary key.
References product .product_id.
|
Product identifier. |
the_year | integer | Primary key. | Year. |
unit_sales | integer | Units sold of the product . |
|
unit_sales_prev | integer | Units sold of the product the previous year. |
|
sales | decimal | Product sales. | |
sales_prev | decimal | Product sales the previous year. | |
sales_pct | decimal | Product sales percentage. | |
sales_avg | decimal | Product sales month average. | |
sales_[mon] | decimal |
Product sales per month of year.
Columns: sales_jan, sales_feb... |
|
cost | decimal | Product cost. | |
cost_prev | decimal | Product cost the previous year. | |
cost_pct | decimal | Product cost percentage. | |
cost_avg | decimal | Product cost month average. | |
cost_[mon] | decimal |
Product cost per month of year.
Columns: cost_jan, cost_feb... |
|
profit | decimal | Product profit = sales - cost. | |
promotion_sales | decimal | Product sales when promotion is applied. |
|
promotion_sales_prev | decimal | Product sales when promotion is applied of previous year. |
|
sales_count | integer | Sales counter. |
sales_fact_month_product
stores yearly information about products and also monthly sales and costs.
Column | Type | Details | Definition |
---|---|---|---|
product_id | integer |
Primary key.
References product .product_id.
|
Product identifier. |
the_year | integer | Primary key. | Year. |
the_month | varchar | Month's name. | |
month_of_year | integer | Primary key. | Month's number. |
unit_sales | integer | Units sold of the product . |
|
unit_sales_prev | integer | Units sold of the product the previous month. |
|
sales | decimal | Product sales. | |
sales_prev | decimal | Product sales the previous month. | |
sales_pct | decimal | Product sales percentage. | |
sales_avg | decimal | Product sales day average. | |
cost | decimal | Product cost. | |
cost_prev | decimal | Product cost the previous month. | |
cost_pct | decimal | Product cost percentage. | |
cost_avg | decimal | Product cost day average. | |
profit | decimal | Product profit = sales - cost. | |
promotion_sales | decimal | Product sales when promotion is applied. |
|
promotion_sales_prev | decimal | Product sales when promotion is applied of previous month. |
|
sales_count | integer | Sales counter. |
sales_fact_yearmonth_product
provides monthly information about products.
2.4 Customer
In this section all the tables associated with customer
will be placed here.
-- ************************************************************************** -- DEISTER WebStudio XSQL-SCHEMA Fri Jun 21 13:08:48 CEST 2019 Engine: informix -- customer -- ************************************************************************** CREATE TABLE customer ( customer_id integer not null, fullname varchar(30) not null, lname varchar(30) not null, fname varchar(30) not null, account_num int8 not null, mi varchar(30), address1 varchar(30), address2 varchar(30), address3 varchar(30), address4 varchar(30), city varchar(30), state_province varchar(30), postal_code varchar(30) not null, country varchar(30) not null, customer_region_id integer not null, phone1 varchar(30) not null, phone2 varchar(30) not null, birthdate date not null, marital_status varchar(30) not null, income_id integer, gender varchar(30) not null, total_children smallint not null, num_children_at_home smallint not null, education varchar(30) not null, date_accnt_opened date not null, member_card varchar(30), occupation varchar(30), houseowner varchar(30), num_cars_owned integer ); ALTER TABLE customer LOCK MODE (ROW); -- Index to avoid automatic named by database (named with pk name). CREATE UNIQUE INDEX p_customer ON customer(customer_id); ALTER TABLE customer ADD CONSTRAINT PRIMARY KEY (customer_id) CONSTRAINT p_customer; CREATE INDEX f_customer_1 ON customer(customer_region_id); ALTER TABLE customer ADD CONSTRAINT FOREIGN KEY (customer_region_id) REFERENCES region(region_id) CONSTRAINT f_customer_1; CREATE INDEX f_customer_2 ON customer(income_id); ALTER TABLE customer ADD CONSTRAINT FOREIGN KEY (income_id) REFERENCES customer_yearly_income(income_id) CONSTRAINT f_customer_2; -- ************************************************************************** -- DEISTER WebStudio XSQL-SCHEMA Fri Jun 21 13:09:09 CEST 2019 Engine: informix -- sales_fact_month_customer -- ************************************************************************** CREATE TABLE sales_fact_month_customer ( customer_id integer not null, the_year integer not null, unit_sales integer default 0, unit_sales_prev integer default 0, sales decimal(10,4) default 0.0, sales_prev decimal(10,4) default 0.0, sales_pct decimal(10,4) default 0.0, sales_avg decimal(10,4) default 0.0, sales_jan decimal(10,4) default 0.0, sales_feb decimal(10,4) default 0.0, sales_mar decimal(10,4) default 0.0, sales_apr decimal(10,4) default 0.0, sales_may decimal(10,4) default 0.0, sales_jun decimal(10,4) default 0.0, sales_jul decimal(10,4) default 0.0, sales_ago decimal(10,4) default 0.0, sales_sep decimal(10,4) default 0.0, sales_oct decimal(10,4) default 0.0, sales_nov decimal(10,4) default 0.0, sales_dec decimal(10,4) default 0.0, cost decimal(10,4) default 0.0, cost_jan decimal(10,4) default 0.0, cost_feb decimal(10,4) default 0.0, cost_mar decimal(10,4) default 0.0, cost_apr decimal(10,4) default 0.0, cost_may decimal(10,4) default 0.0, cost_jun decimal(10,4) default 0.0, cost_jul decimal(10,4) default 0.0, cost_ago decimal(10,4) default 0.0, cost_sep decimal(10,4) default 0.0, cost_oct decimal(10,4) default 0.0, cost_nov decimal(10,4) default 0.0, cost_dec decimal(10,4) default 0.0, cost_prev decimal(10,4) default 0.0, cost_pct decimal(10,4) default 0.0, cost_avg decimal(10,4) default 0.0, profit decimal(10,4) default 0.0, promotion_sales decimal(10,4) default 0.0, promotion_sales_prev decimal(10,4) default 0.0, sales_count integer default 0, sales_count_prev integer default 0 ); ALTER TABLE sales_fact_month_customer LOCK MODE (ROW); -- Index to avoid automatic named by database (named with pk name). CREATE UNIQUE INDEX p_sales_fact_month_customer ON sales_fact_month_customer(customer_id, the_year); ALTER TABLE sales_fact_month_customer ADD CONSTRAINT PRIMARY KEY (customer_id, the_year) CONSTRAINT p_sales_fact_month_customer; CREATE INDEX f_sales_fact_month_customer ON sales_fact_month_customer(customer_id); ALTER TABLE sales_fact_month_customer ADD CONSTRAINT FOREIGN KEY (customer_id) REFERENCES customer(customer_id) CONSTRAINT f_sales_fact_month_customer; -- ************************************************************************** -- DEISTER WebStudio XSQL-SCHEMA Fri Jun 21 13:09:29 CEST 2019 Engine: informix -- sales_fact_yearmonth_customer -- ************************************************************************** CREATE TABLE sales_fact_yearmonth_customer ( customer_id integer not null, the_year integer not null, the_month varchar(30) not null, month_of_year integer not null, unit_sales integer default 0, unit_sales_prev integer default 0, sales decimal(10,4) default 0.0, sales_prev decimal(10,4) default 0.0, sales_pct decimal(10,4) default 0.0, sales_avg decimal(10,4) default 0.0, cost decimal(10,4) default 0.0, cost_prev decimal(10,4) default 0.0, cost_pct decimal(10,4) default 0.0, cost_avg decimal(10,4) default 0.0, profit decimal(10,4) default 0.0, promotion_sales decimal(10,4) default 0.0, promotion_sales_prev decimal(10,4) default 0.0, sales_count integer default 0, sales_count_prev integer default 0 ); ALTER TABLE sales_fact_yearmonth_customer LOCK MODE (ROW); -- Index to avoid automatic named by database (named with pk name). CREATE UNIQUE INDEX p_sales_fact_yearmonth_customer ON sales_fact_yearmonth_customer(customer_id, the_year, month_of_year); ALTER TABLE sales_fact_yearmonth_customer ADD CONSTRAINT PRIMARY KEY (customer_id, the_year, month_of_year) CONSTRAINT p_sales_fact_yearmonth_customer; CREATE INDEX f_sales_fact_yearmonth_customer ON sales_fact_yearmonth_customer(customer_id); ALTER TABLE sales_fact_yearmonth_customer ADD CONSTRAINT FOREIGN KEY (customer_id) REFERENCES customer(customer_id) CONSTRAINT f_sales_fact_yearmonth_customer;
-- ************************************************************************** -- DEISTER WebStudio XSQL-SCHEMA Fri Jun 21 13:08:55 CEST 2019 Engine: postgres -- customer -- ************************************************************************** CREATE TABLE customer ( customer_id integer not null, fullname varchar(30) not null, lname varchar(30) not null, fname varchar(30) not null, account_num int8 not null, mi varchar(30), address1 varchar(30), address2 varchar(30), address3 varchar(30), address4 varchar(30), city varchar(30), state_province varchar(30), postal_code varchar(30) not null, country varchar(30) not null, customer_region_id integer not null, phone1 varchar(30) not null, phone2 varchar(30) not null, birthdate date not null, marital_status varchar(30) not null, income_id integer, gender varchar(30) not null, total_children smallint not null, num_children_at_home smallint not null, education varchar(30) not null, date_accnt_opened date not null, member_card varchar(30), occupation varchar(30), houseowner varchar(30), num_cars_owned integer ) WITH OIDS; -- Database Server on Postgres, DB2 will be created a index automatically with the same name of pk ALTER TABLE customer ADD CONSTRAINT p_customer PRIMARY KEY (customer_id); CREATE INDEX f_customer_1 ON customer(customer_region_id); ALTER TABLE customer ADD CONSTRAINT f_customer_1 FOREIGN KEY (customer_region_id) REFERENCES region(region_id) DEFERRABLE INITIALLY IMMEDIATE ; CREATE INDEX f_customer_2 ON customer(income_id); ALTER TABLE customer ADD CONSTRAINT f_customer_2 FOREIGN KEY (income_id) REFERENCES customer_yearly_income(income_id) DEFERRABLE INITIALLY IMMEDIATE ; -- ************************************************************************** -- DEISTER WebStudio XSQL-SCHEMA Fri Jun 21 13:09:19 CEST 2019 Engine: postgres -- sales_fact_month_customer -- ************************************************************************** CREATE TABLE sales_fact_month_customer ( customer_id integer not null, the_year integer not null, unit_sales integer default 0, unit_sales_prev integer default 0, sales decimal(10,4) default 0.0, sales_prev decimal(10,4) default 0.0, sales_pct decimal(10,4) default 0.0, sales_avg decimal(10,4) default 0.0, sales_jan decimal(10,4) default 0.0, sales_feb decimal(10,4) default 0.0, sales_mar decimal(10,4) default 0.0, sales_apr decimal(10,4) default 0.0, sales_may decimal(10,4) default 0.0, sales_jun decimal(10,4) default 0.0, sales_jul decimal(10,4) default 0.0, sales_ago decimal(10,4) default 0.0, sales_sep decimal(10,4) default 0.0, sales_oct decimal(10,4) default 0.0, sales_nov decimal(10,4) default 0.0, sales_dec decimal(10,4) default 0.0, cost decimal(10,4) default 0.0, cost_jan decimal(10,4) default 0.0, cost_feb decimal(10,4) default 0.0, cost_mar decimal(10,4) default 0.0, cost_apr decimal(10,4) default 0.0, cost_may decimal(10,4) default 0.0, cost_jun decimal(10,4) default 0.0, cost_jul decimal(10,4) default 0.0, cost_ago decimal(10,4) default 0.0, cost_sep decimal(10,4) default 0.0, cost_oct decimal(10,4) default 0.0, cost_nov decimal(10,4) default 0.0, cost_dec decimal(10,4) default 0.0, cost_prev decimal(10,4) default 0.0, cost_pct decimal(10,4) default 0.0, cost_avg decimal(10,4) default 0.0, profit decimal(10,4) default 0.0, promotion_sales decimal(10,4) default 0.0, promotion_sales_prev decimal(10,4) default 0.0, sales_count integer default 0, sales_count_prev integer default 0 ) WITH OIDS; -- Database Server on Postgres, DB2 will be created a index automatically with the same name of pk ALTER TABLE sales_fact_month_customer ADD CONSTRAINT p_sales_fact_month_customer PRIMARY KEY (customer_id, the_year); CREATE INDEX f_sales_fact_month_customer ON sales_fact_month_customer(customer_id); ALTER TABLE sales_fact_month_customer ADD CONSTRAINT f_sales_fact_month_customer FOREIGN KEY (customer_id) REFERENCES customer(customer_id) DEFERRABLE INITIALLY IMMEDIATE ; -- ************************************************************************** -- DEISTER WebStudio XSQL-SCHEMA Fri Jun 21 13:09:37 CEST 2019 Engine: postgres -- sales_fact_yearmonth_customer -- ************************************************************************** CREATE TABLE sales_fact_yearmonth_customer ( customer_id integer not null, the_year integer not null, the_month varchar(30) not null, month_of_year integer not null, unit_sales integer default 0, unit_sales_prev integer default 0, sales decimal(10,4) default 0.0, sales_prev decimal(10,4) default 0.0, sales_pct decimal(10,4) default 0.0, sales_avg decimal(10,4) default 0.0, cost decimal(10,4) default 0.0, cost_prev decimal(10,4) default 0.0, cost_pct decimal(10,4) default 0.0, cost_avg decimal(10,4) default 0.0, profit decimal(10,4) default 0.0, promotion_sales decimal(10,4) default 0.0, promotion_sales_prev decimal(10,4) default 0.0, sales_count integer default 0, sales_count_prev integer default 0 ) WITH OIDS; -- Database Server on Postgres, DB2 will be created a index automatically with the same name of pk ALTER TABLE sales_fact_yearmonth_customer ADD CONSTRAINT p_sales_fact_yearmonth_customer PRIMARY KEY (customer_id, the_year, month_of_year); CREATE INDEX f_sales_fact_yearmonth_customer ON sales_fact_yearmonth_customer(customer_id); ALTER TABLE sales_fact_yearmonth_customer ADD CONSTRAINT f_sales_fact_yearmonth_customer FOREIGN KEY (customer_id) REFERENCES customer(customer_id) DEFERRABLE INITIALLY IMMEDIATE ;
Column | Type | Details | Definition |
---|---|---|---|
customer_id | integer | Primary key. | Customer identifier. |
account_number | bigint | Customer's account number. | |
lname | varchar | Last name. | |
fname | varchar | First name. | |
mi | varchar | Middle Initial. | |
address[number] | varchar |
Customer's address. There are four of them
Columns: address1, address2... |
|
city | varchar | Customer's city. | |
state_province | varchar | Customer's state province. | |
postal_code | varchar | Customer's postal code. | |
country | decimal | Customer's country. | |
customer_region_id | decimal | Refers to region .region_id |
Product's net weight. |
phone[number] | varchar |
Customer's telephone number. There's two of them.
Columns: phone1, phone2 |
|
birthdate | date | Customer's birth date. | |
marital_status | varchar | Customer's marital status. | |
yearly_income | varchar | Customer's yearly income. | |
gender | varchar | Customer's gender. | |
total_children | smallint | Customer's number of children. | |
num_children_at_home | smallint | Customer's number of children at home. | |
education | varchar | Customer's education. | |
date_accnt_opened | varchar | Date customer opened account. |
|
member_card | varchar | Customer's type of membership card. | |
occupation | varchar | Customer's occupation. | |
houseowner | varchar | Whether or not customer owns a house. |
|
num_cars_owned | integer | Number of cars customer owns. |
|
fullname | varchar | Customer's fullname. |
customer
provides the customers information.
Column | Type | Details | Definition |
---|---|---|---|
customer_id | integer |
Primary key.
References customer .customer_id.
|
Customer identifier. |
the_year | integer | Primary key. | Year. |
unit_sales | integer | Units sold of the customer . |
|
unit_sales_prev | integer | Units sold of the customer the previous year. |
|
sales | decimal | Customer sales. | |
sales_prev | decimal | Customer sales the previous year. | |
sales_pct | decimal | Customer sales percentage. | |
sales_avg | decimal | Customer sales month average. | |
sales_[mon] | decimal |
Customer sales per month of year.
Example: sales_jan, sales_feb... |
|
cost | decimal | Customer cost. | |
cost_prev | decimal | Customer cost the previous year. | |
cost_pct | decimal | Customer cost percentage. | |
cost_avg | decimal | Customer cost month average. | |
cost_[mon] | decimal |
Customer cost per month of year.
Example: cost_jan, cost_feb... |
|
profit | decimal | Customer profit = sales - cost. | |
promotion_sales | decimal | Customer sales when promotion is applied. |
|
promotion_sales_prev | decimal | Customer sales when promotion is applied of previous year. |
|
sales_count | integer | Sales counter. |
sales_fact_month_customer
stores yearly information about customers and also monthly sales and costs.
Column | Type | Details | Definition |
---|---|---|---|
customer_id | integer |
Primary key.
References customer .customer_id.
|
Customer identifier. |
the_year | integer | Primary key. | Year. |
the_month | varchar | Month's name. | |
month_of_year | integer | Primary key. | Month's number. |
unit_sales | integer | Units sold of the customer . |
|
unit_sales_prev | integer | Units sold of the customer the previous month. |
|
sales | decimal | Customer sales. | |
sales_prev | decimal | Customer sales the previous month. | |
sales_pct | decimal | Customer sales percentage. | |
sales_avg | decimal | Customer sales day average. | |
cost | decimal | Customer cost. | |
cost_prev | decimal | Customer cost the previous month. | |
cost_pct | decimal | Customer cost percentage. | |
cost_avg | decimal | Customer cost day average. | |
profit | decimal | Customer profit = sales - cost. | |
promotion_sales | decimal | Customer sales when promotion is applied. |
|
promotion_sales_prev | decimal | Customer sales when promotion is applied of previous month. |
|
sales_count | integer | Sales counter. |
sales_fact_yearmonth_customer
provides monthly information about customers.
2.5 Store
In this section all the tables associated with store
will be placed here.
-- ************************************************************************** -- DEISTER WebStudio XSQL-SCHEMA Fri Jun 21 15:59:12 CEST 2019 Engine: informix -- warehouse_class -- ************************************************************************** CREATE TABLE warehouse_class ( warehouse_class_id integer not null, warehouse_name varchar(30) ); ALTER TABLE warehouse_class LOCK MODE (ROW); -- Index to avoid automatic named by database (named with pk name). CREATE UNIQUE INDEX p_warehouse_class ON warehouse_class(warehouse_class_id); ALTER TABLE warehouse_class ADD CONSTRAINT PRIMARY KEY (warehouse_class_id) CONSTRAINT p_warehouse_class; -- ************************************************************************** -- DEISTER WebStudio XSQL-SCHEMA Fri Jun 21 15:56:02 CEST 2019 Engine: informix -- warehouse -- ************************************************************************** CREATE TABLE warehouse ( warehouse_id integer not null, warehouse_class_id integer, stores_id integer, warehouse_name varchar(60), wa_address1 varchar(30), wa_address2 varchar(30), wa_address3 varchar(30), wa_address4 varchar(30), warehouse_city varchar(30), warehouse_state_province varchar(30), warehouse_postal_code varchar(30), warehouse_country varchar(30), warehouse_owner_name varchar(30), warehouse_phone varchar(30), warehouse_fax varchar(30) ); ALTER TABLE warehouse LOCK MODE (ROW); -- Index to avoid automatic named by database (named with pk name). CREATE UNIQUE INDEX p_warehouse ON warehouse(warehouse_id); ALTER TABLE warehouse ADD CONSTRAINT PRIMARY KEY (warehouse_id) CONSTRAINT p_warehouse; -- ************************************************************************** -- DEISTER WebStudio XSQL-SCHEMA Fri Jun 21 16:00:08 CEST 2019 Engine: informix -- department -- ************************************************************************** CREATE TABLE department ( department_id integer not null, department_description varchar(30) not null, state char(1) default 'A' not null ); ALTER TABLE department LOCK MODE (ROW); -- ************************************************************************** -- DEISTER WebStudio XSQL-SCHEMA Fri Jun 21 16:00:28 CEST 2019 Engine: informix -- position -- ************************************************************************** CREATE TABLE position ( position_id integer not null, position_title varchar(30) not null, pay_type varchar(30) not null, min_scale decimal(10,4) not null, max_scale decimal(10,4) not null, management_role varchar(30) not null ); ALTER TABLE position LOCK MODE (ROW); -- ************************************************************************** -- DEISTER WebStudio XSQL-SCHEMA Fri Jun 21 16:00:50 CEST 2019 Engine: informix -- employee -- ************************************************************************** CREATE TABLE employee ( employee_id integer not null, full_name varchar(30) not null, first_name varchar(30) not null, last_name varchar(30) not null, position_id integer, position_title varchar(30), store_id integer not null, department_id integer not null, birth_date date not null, hire_date datetime year to second, end_date datetime year to second, salary decimal(10,4) not null, supervisor_id integer, education_level varchar(30) not null, marital_status varchar(30) not null, gender varchar(30) not null, management_role varchar(30), state char(1) default 'A' not null ); ALTER TABLE employee LOCK MODE (ROW); -- Index to avoid automatic named by database (named with pk name). CREATE UNIQUE INDEX p_employee ON employee(employee_id); ALTER TABLE employee ADD CONSTRAINT PRIMARY KEY (employee_id) CONSTRAINT p_employee; CREATE INDEX f_employee_1 ON employee(store_id); ALTER TABLE employee ADD CONSTRAINT FOREIGN KEY (store_id) REFERENCES store(store_id) CONSTRAINT f_employee_1; CREATE INDEX f_employee_2 ON employee(position_id); ALTER TABLE employee ADD CONSTRAINT FOREIGN KEY (position_id) REFERENCES position(position_id) CONSTRAINT f_employee_2; CREATE INDEX f_employee_3 ON employee(supervisor_id); ALTER TABLE employee ADD CONSTRAINT FOREIGN KEY (supervisor_id) REFERENCES employee(employee_id) CONSTRAINT f_employee_3; CREATE INDEX f_employee_4 ON employee(department_id); ALTER TABLE employee ADD CONSTRAINT FOREIGN KEY (department_id) REFERENCES department(department_id) CONSTRAINT f_employee_4; -- ************************************************************************** -- DEISTER WebStudio XSQL-SCHEMA Fri Jun 21 16:01:28 CEST 2019 Engine: informix -- store -- ************************************************************************** CREATE TABLE store ( store_id serial not null, store_type varchar(30), region_id integer, store_name varchar(30), store_number integer, store_street_address varchar(30), store_city varchar(30), store_state varchar(30), store_postal_code varchar(30), store_country varchar(30), store_manager varchar(30), store_phone varchar(30), store_fax varchar(30), first_opened_date datetime year to second, last_remodel_date datetime year to second, store_sqft integer, grocery_sqft integer, frozen_sqft integer, meat_sqft integer, coffee_bar boolean, video_store boolean, salad_bar boolean, prepared_food boolean, florist boolean, state char(1) default 'A' not null ); ALTER TABLE store LOCK MODE (ROW); -- Index to avoid automatic named by database (named with pk name). CREATE UNIQUE INDEX p_store ON store(store_id); ALTER TABLE store ADD CONSTRAINT PRIMARY KEY (store_id) CONSTRAINT p_store; CREATE INDEX f_store_1 ON store(region_id); ALTER TABLE store ADD CONSTRAINT FOREIGN KEY (region_id) REFERENCES region(region_id) CONSTRAINT f_store_1; -- ************************************************************************** -- DEISTER WebStudio XSQL-SCHEMA Fri Jun 21 16:02:07 CEST 2019 Engine: informix -- sales_fact_month_store -- ************************************************************************** CREATE TABLE sales_fact_month_store ( store_id integer not null, the_year integer not null, unit_sales integer default 0, unit_sales_prev integer default 0, sales decimal(10,4) default 0.0, sales_prev decimal(10,4) default 0.0, sales_pct decimal(10,4) default 0.0, sales_avg decimal(10,4) default 0.0, sales_jan decimal(10,4) default 0.0, sales_feb decimal(10,4) default 0.0, sales_mar decimal(10,4) default 0.0, sales_apr decimal(10,4) default 0.0, sales_may decimal(10,4) default 0.0, sales_jun decimal(10,4) default 0.0, sales_jul decimal(10,4) default 0.0, sales_ago decimal(10,4) default 0.0, sales_sep decimal(10,4) default 0.0, sales_oct decimal(10,4) default 0.0, sales_nov decimal(10,4) default 0.0, sales_dec decimal(10,4) default 0.0, cost decimal(10,4) default 0.0, cost_jan decimal(10,4) default 0.0, cost_feb decimal(10,4) default 0.0, cost_mar decimal(10,4) default 0.0, cost_apr decimal(10,4) default 0.0, cost_may decimal(10,4) default 0.0, cost_jun decimal(10,4) default 0.0, cost_jul decimal(10,4) default 0.0, cost_ago decimal(10,4) default 0.0, cost_sep decimal(10,4) default 0.0, cost_oct decimal(10,4) default 0.0, cost_nov decimal(10,4) default 0.0, cost_dec decimal(10,4) default 0.0, cost_prev decimal(10,4) default 0.0, cost_pct decimal(10,4) default 0.0, cost_avg decimal(10,4) default 0.0, profit decimal(10,4) default 0.0, promotion_sales decimal(10,4) default 0.0, promotion_sales_prev decimal(10,4) default 0.0, sales_count integer default 0, sales_count_prev integer default 0 ); ALTER TABLE sales_fact_month_store LOCK MODE (ROW); -- Index to avoid automatic named by database (named with pk name). CREATE UNIQUE INDEX p_sales_fact_month_store ON sales_fact_month_store(store_id, the_year); ALTER TABLE sales_fact_month_store ADD CONSTRAINT PRIMARY KEY (store_id, the_year) CONSTRAINT p_sales_fact_month_store; CREATE INDEX f_sales_fact_month_store ON sales_fact_month_store(store_id); ALTER TABLE sales_fact_month_store ADD CONSTRAINT FOREIGN KEY (store_id) REFERENCES store(store_id) CONSTRAINT f_sales_fact_month_store; -- ************************************************************************** -- DEISTER WebStudio XSQL-SCHEMA Fri Jun 21 16:02:41 CEST 2019 Engine: informix -- sales_fact_yearmonth_store -- ************************************************************************** CREATE TABLE sales_fact_yearmonth_store ( store_id integer not null, the_year integer not null, the_month varchar(30) not null, month_of_year integer not null, unit_sales integer default 0, unit_sales_prev integer default 0, sales decimal(10,4) default 0.0, sales_prev decimal(10,4) default 0.0, sales_pct decimal(10,4) default 0.0, sales_avg decimal(10,4) default 0.0, cost decimal(10,4) default 0.0, cost_prev decimal(10,4) default 0.0, cost_pct decimal(10,4) default 0.0, cost_avg decimal(10,4) default 0.0, profit decimal(10,4) default 0.0, promotion_sales decimal(10,4) default 0.0, promotion_sales_prev decimal(10,4) default 0.0, sales_count integer default 0, sales_count_prev integer default 0 ); ALTER TABLE sales_fact_yearmonth_store LOCK MODE (ROW); -- Index to avoid automatic named by database (named with pk name). CREATE UNIQUE INDEX p_sales_fact_yearmonth_store ON sales_fact_yearmonth_store(store_id, the_year, month_of_year); ALTER TABLE sales_fact_yearmonth_store ADD CONSTRAINT PRIMARY KEY (store_id, the_year, month_of_year) CONSTRAINT p_sales_fact_yearmonth_store; CREATE INDEX f_sales_fact_yearmonth_store ON sales_fact_yearmonth_store(store_id); ALTER TABLE sales_fact_yearmonth_store ADD CONSTRAINT FOREIGN KEY (store_id) REFERENCES store(store_id) CONSTRAINT f_sales_fact_yearmonth_store;
-- ************************************************************************** -- DEISTER WebStudio XSQL-SCHEMA Fri Jun 21 15:59:30 CEST 2019 Engine: postgres -- warehouse_class -- ************************************************************************** CREATE TABLE warehouse_class ( warehouse_class_id integer not null, warehouse_name varchar(30) ) WITH OIDS; -- Database Server on Postgres, DB2 will be created a index automatically with the same name of pk ALTER TABLE warehouse_class ADD CONSTRAINT p_warehouse_class PRIMARY KEY (warehouse_class_id); -- ************************************************************************** -- DEISTER WebStudio XSQL-SCHEMA Fri Jun 21 15:56:20 CEST 2019 Engine: postgres -- warehouse -- ************************************************************************** CREATE TABLE warehouse ( warehouse_id integer not null, warehouse_class_id integer, stores_id integer, warehouse_name varchar(60), wa_address1 varchar(30), wa_address2 varchar(30), wa_address3 varchar(30), wa_address4 varchar(30), warehouse_city varchar(30), warehouse_state_province varchar(30), warehouse_postal_code varchar(30), warehouse_country varchar(30), warehouse_owner_name varchar(30), warehouse_phone varchar(30), warehouse_fax varchar(30) ) WITH OIDS; -- Database Server on Postgres, DB2 will be created a index automatically with the same name of pk ALTER TABLE warehouse ADD CONSTRAINT p_warehouse PRIMARY KEY (warehouse_id); -- ************************************************************************** -- DEISTER WebStudio XSQL-SCHEMA Fri Jun 21 16:00:15 CEST 2019 Engine: postgres -- department -- ************************************************************************** CREATE TABLE department ( department_id integer not null, department_description varchar(30) not null, state varchar(1) default 'A' not null ) WITH OIDS; -- ************************************************************************** -- DEISTER WebStudio XSQL-SCHEMA Fri Jun 21 16:00:35 CEST 2019 Engine: postgres -- position -- ************************************************************************** CREATE TABLE position ( position_id integer not null, position_title varchar(30) not null, pay_type varchar(30) not null, min_scale decimal(10,4) not null, max_scale decimal(10,4) not null, management_role varchar(30) not null ) WITH OIDS; -- ************************************************************************** -- DEISTER WebStudio XSQL-SCHEMA Fri Jun 21 16:00:56 CEST 2019 Engine: postgres -- employee -- ************************************************************************** CREATE TABLE employee ( employee_id integer not null, full_name varchar(30) not null, first_name varchar(30) not null, last_name varchar(30) not null, position_id integer, position_title varchar(30), store_id integer not null, department_id integer not null, birth_date date not null, hire_date timestamp, end_date timestamp, salary decimal(10,4) not null, supervisor_id integer, education_level varchar(30) not null, marital_status varchar(30) not null, gender varchar(30) not null, management_role varchar(30), state varchar(1) default 'A' not null ) WITH OIDS; -- Database Server on Postgres, DB2 will be created a index automatically with the same name of pk ALTER TABLE employee ADD CONSTRAINT p_employee PRIMARY KEY (employee_id); CREATE INDEX f_employee_1 ON employee(store_id); ALTER TABLE employee ADD CONSTRAINT f_employee_1 FOREIGN KEY (store_id) REFERENCES store(store_id) DEFERRABLE INITIALLY IMMEDIATE ; CREATE INDEX f_employee_2 ON employee(position_id); ALTER TABLE employee ADD CONSTRAINT f_employee_2 FOREIGN KEY (position_id) REFERENCES position(position_id) DEFERRABLE INITIALLY IMMEDIATE ; CREATE INDEX f_employee_3 ON employee(supervisor_id); ALTER TABLE employee ADD CONSTRAINT f_employee_3 FOREIGN KEY (supervisor_id) REFERENCES employee(employee_id) DEFERRABLE INITIALLY IMMEDIATE ; CREATE INDEX f_employee_4 ON employee(department_id); ALTER TABLE employee ADD CONSTRAINT f_employee_4 FOREIGN KEY (department_id) REFERENCES department(department_id) DEFERRABLE INITIALLY IMMEDIATE ; -- ************************************************************************** -- DEISTER WebStudio XSQL-SCHEMA Fri Jun 21 16:01:39 CEST 2019 Engine: postgres -- store -- ************************************************************************** CREATE TABLE store ( store_id serial not null, store_type varchar(30), region_id integer, store_name varchar(30), store_number integer, store_street_address varchar(30), store_city varchar(30), store_state varchar(30), store_postal_code varchar(30), store_country varchar(30), store_manager varchar(30), store_phone varchar(30), store_fax varchar(30), first_opened_date timestamp, last_remodel_date timestamp, store_sqft integer, grocery_sqft integer, frozen_sqft integer, meat_sqft integer, coffee_bar boolean, video_store boolean, salad_bar boolean, prepared_food boolean, florist boolean, state varchar(1) default 'A' not null ) WITH OIDS; -- Database Server on Postgres, DB2 will be created a index automatically with the same name of pk ALTER TABLE store ADD CONSTRAINT p_store PRIMARY KEY (store_id); CREATE INDEX f_store_1 ON store(region_id); ALTER TABLE store ADD CONSTRAINT f_store_1 FOREIGN KEY (region_id) REFERENCES region(region_id) DEFERRABLE INITIALLY IMMEDIATE ; -- ************************************************************************** -- DEISTER WebStudio XSQL-SCHEMA Fri Jun 21 16:02:17 CEST 2019 Engine: postgres -- sales_fact_month_store -- ************************************************************************** CREATE TABLE sales_fact_month_store ( store_id integer not null, the_year integer not null, unit_sales integer default 0, unit_sales_prev integer default 0, sales decimal(10,4) default 0.0, sales_prev decimal(10,4) default 0.0, sales_pct decimal(10,4) default 0.0, sales_avg decimal(10,4) default 0.0, sales_jan decimal(10,4) default 0.0, sales_feb decimal(10,4) default 0.0, sales_mar decimal(10,4) default 0.0, sales_apr decimal(10,4) default 0.0, sales_may decimal(10,4) default 0.0, sales_jun decimal(10,4) default 0.0, sales_jul decimal(10,4) default 0.0, sales_ago decimal(10,4) default 0.0, sales_sep decimal(10,4) default 0.0, sales_oct decimal(10,4) default 0.0, sales_nov decimal(10,4) default 0.0, sales_dec decimal(10,4) default 0.0, cost decimal(10,4) default 0.0, cost_jan decimal(10,4) default 0.0, cost_feb decimal(10,4) default 0.0, cost_mar decimal(10,4) default 0.0, cost_apr decimal(10,4) default 0.0, cost_may decimal(10,4) default 0.0, cost_jun decimal(10,4) default 0.0, cost_jul decimal(10,4) default 0.0, cost_ago decimal(10,4) default 0.0, cost_sep decimal(10,4) default 0.0, cost_oct decimal(10,4) default 0.0, cost_nov decimal(10,4) default 0.0, cost_dec decimal(10,4) default 0.0, cost_prev decimal(10,4) default 0.0, cost_pct decimal(10,4) default 0.0, cost_avg decimal(10,4) default 0.0, profit decimal(10,4) default 0.0, promotion_sales decimal(10,4) default 0.0, promotion_sales_prev decimal(10,4) default 0.0, sales_count integer default 0, sales_count_prev integer default 0 ) WITH OIDS; -- Database Server on Postgres, DB2 will be created a index automatically with the same name of pk ALTER TABLE sales_fact_month_store ADD CONSTRAINT p_sales_fact_month_store PRIMARY KEY (store_id, the_year); CREATE INDEX f_sales_fact_month_store ON sales_fact_month_store(store_id); ALTER TABLE sales_fact_month_store ADD CONSTRAINT f_sales_fact_month_store FOREIGN KEY (store_id) REFERENCES store(store_id) DEFERRABLE INITIALLY IMMEDIATE ; -- ************************************************************************** -- DEISTER WebStudio XSQL-SCHEMA Fri Jun 21 16:02:51 CEST 2019 Engine: postgres -- sales_fact_yearmonth_store -- ************************************************************************** CREATE TABLE sales_fact_yearmonth_store ( store_id integer not null, the_year integer not null, the_month varchar(30) not null, month_of_year integer not null, unit_sales integer default 0, unit_sales_prev integer default 0, sales decimal(10,4) default 0.0, sales_prev decimal(10,4) default 0.0, sales_pct decimal(10,4) default 0.0, sales_avg decimal(10,4) default 0.0, cost decimal(10,4) default 0.0, cost_prev decimal(10,4) default 0.0, cost_pct decimal(10,4) default 0.0, cost_avg decimal(10,4) default 0.0, profit decimal(10,4) default 0.0, promotion_sales decimal(10,4) default 0.0, promotion_sales_prev decimal(10,4) default 0.0, sales_count integer default 0, sales_count_prev integer default 0 ) WITH OIDS; -- Database Server on Postgres, DB2 will be created a index automatically with the same name of pk ALTER TABLE sales_fact_yearmonth_store ADD CONSTRAINT p_sales_fact_yearmonth_store PRIMARY KEY (store_id, the_year, month_of_year); CREATE INDEX f_sales_fact_yearmonth_store ON sales_fact_yearmonth_store(store_id); ALTER TABLE sales_fact_yearmonth_store ADD CONSTRAINT f_sales_fact_yearmonth_store FOREIGN KEY (store_id) REFERENCES store(store_id) DEFERRABLE INITIALLY IMMEDIATE ;
Column | Type | Details | Definition |
---|---|---|---|
warehouse_class_id | integer | Primary key. | Warehouse class identifier. |
description | varchar | Warehouse class description. |
warehouse_class
provides description of the warehouses.
Column | Type | Details | Definition |
---|---|---|---|
warehouse_id | integer | Primary key. | Warehouse identifier. |
warehouse_class_id | integer | References to warehouse_class .warehouse_class_id. |
Warehouse class identifier. |
stores_id | integer | References to store .store_id |
Store identifier. |
warehouse_name | varchar | Warehouse name. | |
wa_address[number] | varchar |
Warehouse address. There are four of them.
Columns: wa_address1, wa_address2... |
|
warehouse_city | varchar | Warehouse's city. | |
warehouse_state_province | varchar | Warehouse's state province. | |
warehouse_postal_code | varchar | Warehouse's postal code. | |
warehouse_country | decimal | Warehouse's country. | |
warehouse_owner_name | varchar | Warehouse owner's name. | |
warehouse_phone | varchar | Warehouse's telephone number. | |
warehouse_fax | varchar | Warehouse's fax number. |
warehouse
stores information about the warehouses location and owner
Column | Type | Details | Definition |
---|---|---|---|
department_id | integer | Primary key. | Department identifier. |
department_description | varchar | Department description. | |
state | char | State of the department . |
department
stores types of departments for the employee
table to use.
Column | Type | Details | Definition |
---|---|---|---|
position_id | integer | Position identifier. | |
position_title | varchar | Position title. | |
pay_type | varchar | Payment type. | |
min_scale | decimal | Minimum scale. | |
max_scale | decimal | Maximum scale. | |
management_role | varchar | Management role. |
position provides types of positions for the employee
table to use.
Column | Type | Details | Definition |
---|---|---|---|
employee_id | integer | Primary key. | Employee identifier. |
full_name | varchar | Employee name. | |
first_name | varchar | First name. | |
last_name | varchar | Last name. | |
position_id | varchar | References to position.position_id | Position identifier. |
position_title | varchar | Position title. | |
stores_id | integer | References to store .store_id |
Store identifier. |
department_id | integer | References to department .department_id |
Department identifier. |
birth_date | date | Employee's birth date. | |
hire_date | datetime | Employee hiring date. | |
end_date | datetime | Employee end of contract date. | |
salary | decimal | Employee's salary. | |
supervisor_id | integer | References to employee .employee_id |
Supervisor identifier. |
education_level | varchar | Employee's education level. | |
marital_status | varchar | Employees's marital status. | |
gender | varchar | Employee's gender. | |
management_role | varchar | Management role. | |
state | char | State of employee . |
employee
stores information about employees and their supervisors.
Column | Type | Details | Definition |
---|---|---|---|
store_id | serial | Primary key. | Store identifier. |
store_type | varchar | Type of store . |
|
store_name | varchar | Store name. | |
store_number | integer | Store number. | |
store_street_address | varchar | Store's address. | |
store_city | varchar | Store's city. | |
store_state | varchar | Store's state province. | |
store_postal_code | varchar | Store's postal code. | |
store_country | varchar | Store's country. | |
store_manager | varchar | Store's manager. | |
store_phone | varchar | Store's telephone number. | |
store_fax | varchar | Store's fax number. | |
first_opened_date | varchar | Date store 's first opening. |
|
store_sqft | integer | Store squared feet. | |
grocery_sqft | integer | Groceries section squared feet. | |
frozen_sqft | integer | Freezers section squared feet. | |
meat_sqft | integer | Meat section squared feet. | |
coffee_bar | boolean | Whether there's coffee bar or not. | |
video_store | boolean | Whether there's video store or not. |
|
salad_bar | boolean | Whether there's salad bar or not. | |
prepared_food | boolean | Whether there's prepared food or not. | |
florist | boolean | Whether there's florist or not. | |
state | char | State of store . |
store
provides information about the stores locations and other facts.
Column | Type | Details | Definition |
---|---|---|---|
store_id | integer |
Primary key.
References store .store_id.
|
Store identifier. |
the_year | integer | Primary key. | Year. |
unit_sales | integer | Units sold of the store . |
|
unit_sales_prev | integer | Units sold of the store the previous year. |
|
sales | decimal | Store sales. | |
sales_prev | decimal | Store sales the previous year. | |
sales_pct | decimal | Store sales percentage. | |
sales_avg | decimal | Store sales month average. | |
sales_[mon] | decimal |
Store sales per month of year.
Example: sales_jan, sales_feb... |
|
cost | decimal | Store cost. | |
cost_prev | decimal | Store cost the previous year. | |
cost_pct | decimal | Store cost percentage. | |
cost_avg | decimal | Store cost month average. | |
cost_[mon] | decimal |
Store cost per month of year.
Example: cost_jan, cost_feb... |
|
profit | decimal | Store profit = sales - cost. | |
promotion_sales | decimal | Store sales when promotion is applied. |
|
promotion_sales_prev | decimal | Store sales when promotion is applied of previous year. |
|
sales_count | integer | Sales counter. |
sales_fact_month_store
stores yearly information about stores and also monthly sales and costs.
Column | Type | Details | Definition |
---|---|---|---|
store_id | integer |
Primary key.
References store .store_id.
|
Store identifier. |
the_year | integer | Primary key. | Year. |
the_month | varchar | Month's name. | |
month_of_year | integer | Primary key. | Month's number. |
unit_sales | integer | Units sold of the store . |
|
unit_sales_prev | integer | Units sold of the store the previous month. |
|
sales | decimal | Store sales. | |
sales_prev | decimal | Store sales the previous month. | |
sales_pct | decimal | Store sales percentage. | |
sales_avg | decimal | Store sales day average. | |
cost | decimal | Store cost. | |
cost_prev | decimal | Store cost the previous month. | |
cost_pct | decimal | Store cost percentage. | |
cost_avg | decimal | Store cost day average. | |
profit | decimal | Store profit = sales - cost. | |
promotion_sales | decimal | Store sales when promotion is applied. |
|
promotion_sales_prev | decimal | Store sales when promotion is applied of previous month. |
|
sales_count | integer | Sales counter. |
sales_fact_yearmonth_store
provides monthly information about stores.
2.6 Other tables
In this section all the tables associated with store
will be placed here.
-- ************************************************************************** -- DEISTER WebStudio XSQL-SCHEMA Fri Jun 21 16:45:56 CEST 2019 Engine: informix -- district -- ************************************************************************** CREATE TABLE district ( district_id serial, district varchar(30), state_province varchar(30), country varchar(30) ); ALTER TABLE district LOCK MODE (ROW); -- Index to avoid automatic named by database (named with pk name). CREATE UNIQUE INDEX p_district ON district(district_id); ALTER TABLE district ADD CONSTRAINT PRIMARY KEY (district_id) CONSTRAINT p_district; -- ************************************************************************** -- DEISTER WebStudio XSQL-SCHEMA Fri Jun 21 17:03:30 CEST 2019 Engine: informix -- region -- ************************************************************************** CREATE TABLE region ( region_id integer not null, sales_city varchar(30), sales_state_province varchar(30), sales_district varchar(30), sales_region varchar(30), sales_country varchar(30), sales_district_id integer ); ALTER TABLE region LOCK MODE (ROW); -- Index to avoid automatic named by database (named with pk name). CREATE UNIQUE INDEX p_region ON region(region_id); ALTER TABLE region ADD CONSTRAINT PRIMARY KEY (region_id) CONSTRAINT p_region; CREATE INDEX f_region_1 ON region(sales_district_id); ALTER TABLE region ADD CONSTRAINT FOREIGN KEY (sales_district_id) REFERENCES district(district_id) CONSTRAINT f_region_1;
-- ************************************************************************** -- DEISTER WebStudio XSQL-SCHEMA Fri Jun 21 16:46:03 CEST 2019 Engine: postgres -- district -- ************************************************************************** CREATE TABLE district ( district_id serial, district varchar(30), state_province varchar(30), country varchar(30) ) WITH OIDS; -- Database Server on Postgres, DB2 will be created a index automatically with the same name of pk ALTER TABLE district ADD CONSTRAINT p_district PRIMARY KEY (district_id); -- ************************************************************************** -- DEISTER WebStudio XSQL-SCHEMA Fri Jun 21 17:03:41 CEST 2019 Engine: postgres -- region -- ************************************************************************** CREATE TABLE region ( region_id integer not null, sales_city varchar(30), sales_state_province varchar(30), sales_district varchar(30), sales_region varchar(30), sales_country varchar(30), sales_district_id integer ) WITH OIDS; -- Database Server on Postgres, DB2 will be created a index automatically with the same name of pk ALTER TABLE region ADD CONSTRAINT p_region PRIMARY KEY (region_id); CREATE INDEX f_region_1 ON region(sales_district_id); ALTER TABLE region ADD CONSTRAINT f_region_1 FOREIGN KEY (sales_district_id) REFERENCES district(district_id) DEFERRABLE INITIALLY IMMEDIATE ;
Column | Type | Details | Definition |
---|---|---|---|
district_id | serial | Primary key. | District identifier. |
district
|
varchar | District name. | |
state_province | varchar | State province. | |
country | varchar | Country. |
district
stores location information about the districts.
Column | Type | Details | Definition |
---|---|---|---|
region_id | serial | Primary key. | Region identifier. |
sales_city | varchar | City. | |
sales_state_province | varchar | State province. | |
sales_district | varchar | District. | |
sales_region | varchar | Sales region . |
|
sales_country | varchar | Sales country. | |
sales_district_id | integer | References to district .district_id. |
District identifier. |
region
stores location information about the regions.
3 Triggers and procedures
The table sales_fact
has three triggers to manage inserts, updates and deletes into the table and also three specific procedures that will help fill the tables sales_fact_month_customer
, sales_fact_month_product
, sales_fact_month_store
and sales_fact_yearmonth_customer
, sales_fact_yearmonth_product
and sales_fact_yearmonth_store
.
3.1 Insert
3.1.1 Trigger
When a new entry is inserted to sales_fact
; sales_fact_month_customer
, sales_fact_month_product
and sales_fact_month_store
update or insert their corresponding entries as well as sales_fact_yearmonth_customer
, sales_fact_yearmonth_product
and sales_fact_yearmonth_store
.
3.1.2 Procedure
The procedure will update already existing rows on sales_fact_month_*
and sales_fact_yearmonth_*
or insert new rows. As the tables have columns for previous months or years, when inserting it will search for a previous year or month to get the values it needs. If found, it will fill in those fields, if not a 0 will be placed in them. The *_prev
columns for the following year or month are also updated (if existing) with the corresponding values of the current year.
3.2 Update
3.2.1 Trigger
When a new entry is updated in sales_fact
; sales_fact_month_customer
, sales_fact_month_product
and sales_fact_month_store
update the old corresponding entries and update or insert the new corresponding entries. The same happens to sales_fact_yearmonth_customer
, sales_fact_yearmonth_product
and sales_fact_yearmonth_store
.
3.2.2 Procedure
Depending on what column is modified, the procedure will either modify the product
tables, the store
tables, the customer
tables or all of them. When doing the modification, it will update the old row to the proper values. Then, it will update or insert a year row in each or the corresponding sales_fact_month_*
and also a month row in the respective sales_fact_yearmonth_*
. As the tables have columns for previous months or years, when inserting it will search for a previous year or month to get the values it needs. If found, it will fill in those fields, if not a 0 will be placed in them. The *_prev
columns for the following year or month are also updated (if existing) with the corresponding values of the current year.
3.3 Delete
3.3.1 Trigger
When an entry is deleted in sales_fact
; sales_fact_month_customer
, sales_fact_month_product
and sales_fact_month_store
update their corresponding entries and do the same in sales_fact_yearmonth_customer
, sales_fact_yearmonth_product
and sales_fact_yearmonth_store
.
3.3.2 Procedure
When deleting, the afected rows in sales_fact_month_*
and sales_fact_yearmonth_*
will be updated to the corresponding values, as well as the *_prev
columns in the following year or month will be updated to the newer values.