From 14cdb55b254b8ab324b08f591e01ff94efdc82f0 Mon Sep 17 00:00:00 2001 From: s26453 Date: Tue, 27 Nov 2018 18:15:18 +0000 Subject: [PATCH] Zaktualizuj 'sql/create.sql' --- sql/create.sql | 170 +++++++++++++++++++++++++++++++------------------ 1 file changed, 107 insertions(+), 63 deletions(-) diff --git a/sql/create.sql b/sql/create.sql index 7ee20ce..f113317 100644 --- a/sql/create.sql +++ b/sql/create.sql @@ -1,64 +1,108 @@ -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, - DrugProductId INTEGER NOT NULL, -- business key - RecordStatus CHAR(1), -- A for active, D for deactivated - DrugProductName NVARCHAR(250), - RONumber NVARCHAR(20), - DrugProductFamilyId INTEGER, - DrugProductFamilyName 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 ( - status_sk INTEGER identity(1, 1) PRIMARY KEY, - status_code 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, status_description) -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, - IndicationId INTEGER NOT NULL, - RecordStatus CHAR(1), - IndicationDescription NVARCHAR(500) -); +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, + DrugProductId INTEGER NOT NULL, -- business key + RecordStatus CHAR(1), -- A for active, D for deactivated + DrugProductName NVARCHAR(250), + RONumber NVARCHAR(20), + DrugProductFamilyId INTEGER, + DrugProductFamilyName 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 ( + status_sk INTEGER identity(1, 1) PRIMARY KEY, + status_code 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, status_description) +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, + IndicationId INTEGER NOT NULL, + RecordStatus CHAR(1), + IndicationDescription 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; + + +DROP TABLE IF EXISTS FT1_Registartion; +CREATE TABLE FT1_Registartion ( + id INTEGER identity(1,1) PRIMARY KEY, + expected_response integer, + submission_date integer, + response_time integer, + drug_sk integer, + factory_sk_API integer, + factory_sk_bulk integer, + factory_sk_package integer, + country_sk integer, + --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_sk integer, + indication_sk integer, + claim number integer, + -- cnt jest tylko zliczeniowy, będzie miał 1, więc dałbym tinyint + cnt tinyint +); +GO + +DROP TABLE IF EXISTS FT2_Refund; +CREATE TABLE FT2_Registartion ( + id INTEGER identity(1,1) PRIMARY KEY, + claim_status_sk integer, + drug_sk integer, + submission_date integer, + expected_response integer, + country_sk integer, + indication_sk integer, + registration_country integer, + --decimal zjada mniej, niż money, do przedyskutowania (precyzja - liczba miejsc przed i po przecinku, skala - liczba miejsc po przecinku) + price decimal(9,2), + reimbursement_amountPercent smallint, + --tu obliczymy jako iloczyn price * reimbursement_amountPercent + reimbursement_amount decimal(9,2), + +); GO \ No newline at end of file