1
0
forked from s26450/hurtownia
hurtownia/sql/create.sql

110 lines
3.0 KiB
MySQL
Raw Normal View History

2018-11-27 19:15:18 +01:00
DROP TABLE IF EXISTS dim_factories;
CREATE TABLE dim_factories (
factory_sk INTEGER identity(1,1) PRIMARY KEY,
factory_bk NVARCHAR(100) NOT NULL,
factory_name NVARCHAR(250),
factory_country NVARCHAR(250)
);
GO
DROP TABLE IF EXISTS dim_time;
CREATE TABLE dim_time (
time_sk INTEGER identity(1,1) PRIMARY KEY,
time_bk DATE NOT NULL,
time_string NCHAR(10) NOT NULL,
year INTEGER,
month INTEGER,
day INTEGER,
quarter INTEGER
);
GO
DROP TABLE IF EXISTS dim_drugs;
CREATE TABLE dim_drugs (
drug_sk INTEGER identity(1, 1) PRIMARY KEY,
2018-12-02 09:46:29 +01:00
drug_product_id_bk INTEGER NOT NULL, -- business key
record_status CHAR(1), -- A for active, D for deactivated
drug_product_name NVARCHAR(250),
ro_number NVARCHAR(20),
drug_product_family_id INTEGER,
drug_product_family_name NVARCHAR(250)
2018-11-27 19:15:18 +01:00
);
GO
DROP TABLE IF EXISTS dim_countries;
CREATE TABLE dim_countries (
country_sk INTEGER identity(1, 1) PRIMARY KEY,
country_code NVARCHAR(2), -- business key
country_name NVARCHAR(250)
);
DROP TABLE IF EXISTS dim_claim_statuses;
CREATE TABLE dim_claim_statuses (
2018-12-02 09:09:37 +01:00
claim_status_sk INTEGER identity(1, 1) PRIMARY KEY,
2018-12-02 09:46:29 +01:00
status_code_bk VARCHAR(1) NOT NULL, -- A for Accepted, D for Declined, W for Waiting
2018-11-27 19:15:18 +01:00
status_description NVARCHAR(50)
);
GO
-- insert statuses
2018-12-02 09:46:29 +01:00
INSERT INTO dim_claim_statuses(status_code_bk, status_description)
2018-11-27 19:15:18 +01:00
VALUES
('A', 'Accepted'),
('D', 'Declined'),
('W', 'Waiting');
GO
DROP TABLE IF EXISTS dim_indications;
CREATE TABLE dim_indications (
indication_sk INTEGER identity(1, 1) PRIMARY KEY,
2018-12-02 09:46:29 +01:00
indication_id_bk INTEGER NOT NULL,
record_status CHAR(1),
indication_description NVARCHAR(500)
2018-11-27 19:15:18 +01:00
);
GO
--TABELE FAKTÓW
--to by było do SQL Server'a < 2016
--IF OBJECT_ID('dbo.FT1_Registartion') IS NOT NULL DROP TABLE dbo.MyCategories;
2018-12-02 09:46:29 +01:00
DROP TABLE IF EXISTS FT1_Registration;
CREATE TABLE FT1_Registration (
2018-11-27 19:15:18 +01:00
id INTEGER identity(1,1) PRIMARY KEY,
2018-12-02 09:46:29 +01:00
expected_response_fk integer,
submission_date_fk integer,
response_time_fk integer,
drug_fk integer,
factory_API_fk integer,
factory_bulk_fk integer,
factory_package_fk integer,
country_fk integer,
2018-11-27 19:15:18 +01:00
--claim status do uspójnienia z tabelą dim_status, wydaje mi się, że można by dodać przedrostek claim do kolumn, będzie czytelniej :)
2018-12-02 09:46:29 +01:00
claim_status_fk integer,
indication_fk integer,
2018-11-27 19:41:55 +01:00
claim_number integer,
2018-11-27 19:15:18 +01:00
-- cnt jest tylko zliczeniowy, będzie miał 1, więc dałbym tinyint
2018-12-02 09:46:29 +01:00
cnt tinyint,
2018-11-27 19:15:18 +01:00
);
GO
DROP TABLE IF EXISTS FT2_Refund;
2018-12-02 09:46:29 +01:00
CREATE TABLE FT2_Refund (
2018-11-27 19:15:18 +01:00
id INTEGER identity(1,1) PRIMARY KEY,
2018-12-02 09:46:29 +01:00
claim_status_fk integer,
drug_fk integer,
submission_date_fk integer,
expected_response_fk integer,
response_time_fk integer,
country_fk integer,
indication_fk integer,
registration_country_fk integer,
2018-11-27 19:15:18 +01:00
--decimal zjada mniej, niż money, do przedyskutowania (precyzja - liczba miejsc przed i po przecinku, skala - liczba miejsc po przecinku)
2018-12-02 09:46:29 +01:00
price money,
2018-11-27 19:15:18 +01:00
reimbursement_amountPercent smallint,
--tu obliczymy jako iloczyn price * reimbursement_amountPercent
reimbursement_amount decimal(9,2),
2018-12-02 09:46:29 +01:00
claim_number integer,
cnt tinyint,
2018-11-27 19:15:18 +01:00
);
2018-11-20 19:11:02 +01:00
GO