forked from s26450/hurtownia
118 lines
4.1 KiB
Transact-SQL
118 lines
4.1 KiB
Transact-SQL
DROP TABLE IF EXISTS FT_Refund;
|
|
DROP TABLE IF EXISTS FT_Registration;
|
|
|
|
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,
|
|
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)
|
|
);
|
|
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 (
|
|
claim_status_sk INTEGER identity(1, 1) PRIMARY KEY,
|
|
status_code_bk VARCHAR(1) NOT NULL, -- A for Accepted, D for Declined, W for Waiting
|
|
status_description NVARCHAR(50)
|
|
);
|
|
GO
|
|
|
|
-- insert statuses
|
|
INSERT INTO dim_claim_statuses(status_code_bk, status_description)
|
|
VALUES
|
|
('A', 'Accepted'),
|
|
('D', 'Declined'),
|
|
('W', 'Waiting');
|
|
GO
|
|
|
|
DROP TABLE IF EXISTS claim_status_mapping;
|
|
CREATE TABLE claim_status_mapping (
|
|
status_code_bk VARCHAR(1),
|
|
status_code_value VARCHAR(50)
|
|
);
|
|
GO
|
|
|
|
DROP TABLE IF EXISTS dim_indications;
|
|
CREATE TABLE dim_indications (
|
|
indication_sk INTEGER identity(1, 1) PRIMARY KEY,
|
|
indication_id_bk INTEGER NOT NULL,
|
|
record_status CHAR(1),
|
|
indication_description NVARCHAR(500)
|
|
);
|
|
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;
|
|
|
|
|
|
CREATE TABLE FT_Registration (
|
|
ft_registration_sk INTEGER identity(1,1) PRIMARY KEY,
|
|
expected_response_time_fk integer FOREIGN KEY REFERENCES dim_time(time_sk) NOT NULL,
|
|
submission_date_fk integer FOREIGN KEY REFERENCES dim_time(time_sk) NOT NULL,
|
|
response_time_fk integer FOREIGN KEY REFERENCES dim_time(time_sk), -- moze byc null
|
|
drug_fk integer FOREIGN KEY REFERENCES dim_drugs(drug_sk) NOT NULL,
|
|
factory_API_fk integer FOREIGN KEY REFERENCES dim_factories(factory_sk) NOT NULL,
|
|
factory_bulk_fk integer FOREIGN KEY REFERENCES dim_factories(factory_sk) NOT NULL,
|
|
factory_package_fk integer FOREIGN KEY REFERENCES dim_factories(factory_sk) NOT NULL,
|
|
country_fk integer FOREIGN KEY REFERENCES dim_countries(country_sk) NOT NULL,
|
|
--claim status do uspójnienia z tabelą dim_status, wydaje mi się, że można by dodać przedrostek claim do kolumn, będzie czytelniej :)
|
|
claim_status_fk integer FOREIGN KEY REFERENCES dim_claim_statuses(claim_status_sk) NOT NULL,
|
|
indication_fk integer FOREIGN KEY REFERENCES dim_indications(indication_sk) NOT NULL,
|
|
claim_number NVARCHAR(50),
|
|
-- cnt jest tylko zliczeniowy, będzie miał 1, więc dałbym tinyint
|
|
cnt tinyint,
|
|
);
|
|
GO
|
|
|
|
CREATE TABLE FT_Refund (
|
|
ft_registartion_sk INTEGER identity(1,1) PRIMARY KEY,
|
|
claim_status_fk integer FOREIGN KEY REFERENCES dim_claim_statuses(claim_status_sk) NOT NULL,
|
|
drug_fk integer FOREIGN KEY REFERENCES dim_drugs(drug_sk) NOT NULL,
|
|
submission_date_fk integer FOREIGN KEY REFERENCES dim_time(time_sk) NOT NULL,
|
|
expected_response_fk integer FOREIGN KEY REFERENCES dim_time(time_sk) NOT NULL,
|
|
response_time_fk integer FOREIGN KEY REFERENCES dim_time(time_sk), -- moze byc null
|
|
country_fk integer FOREIGN KEY REFERENCES dim_countries(country_sk) NOT NULL,
|
|
indication_fk integer FOREIGN KEY REFERENCES dim_indications(indication_sk) NOT NULL,
|
|
registration_country_fk integer FOREIGN KEY REFERENCES dim_countries(country_sk) NOT NULL,
|
|
--decimal zjada mniej, niż money, do przedyskutowania (precyzja - liczba miejsc przed i po przecinku, skala - liczba miejsc po przecinku)
|
|
price money,
|
|
reimbursement_amountPercent smallint,
|
|
--tu obliczymy jako iloczyn price * reimbursement_amountPercent
|
|
reimbursement_amount decimal(9,2),
|
|
claim_number integer,
|
|
cnt tinyint,
|
|
);
|
|
GO |