139 lines
4.0 KiB
SQL
139 lines
4.0 KiB
SQL
CREATE TABLE `fact_service` (
|
|
`service_id` int PRIMARY KEY,
|
|
`inventory_id` int ,
|
|
`service_date` int ,
|
|
`store_id` int ,
|
|
`service_cost` DECIMAL ,
|
|
`service_type_id` int
|
|
);
|
|
|
|
CREATE TABLE `dim_customer` (
|
|
`customer_id` int PRIMARY KEY,
|
|
`name` varchar(64) ,
|
|
`birth_date` DATE ,
|
|
`email` varchar(64) ,
|
|
`address` varchar(64) ,
|
|
`city` varchar(64) ,
|
|
`country` varchar(64) ,
|
|
`postal_code` varchar(64)
|
|
);
|
|
|
|
CREATE TABLE `dim_calendar` (
|
|
`date_id` int PRIMARY KEY,
|
|
`date` DATE ,
|
|
`day_name` varchar(64) ,
|
|
`day_abbrv` varchar(64) ,
|
|
`calendar_month` int ,
|
|
`calendar_quarter` int ,
|
|
`calendar_year` int ,
|
|
`calendar_month_year` int ,
|
|
`is_weekend` BOOLEAN ,
|
|
`month_end` BOOLEAN ,
|
|
`week_num` int
|
|
);
|
|
|
|
CREATE TABLE `fact_rentals` (
|
|
`rental_id` int PRIMARY KEY,
|
|
`customer_id` int ,
|
|
`store_id` int ,
|
|
`staff_id` int ,
|
|
`inventory_id` int ,
|
|
`equipment_hash_FK` INT ,
|
|
`rent_start` int ,
|
|
`rent_end` int ,
|
|
`payment_date` int ,
|
|
`payment_deadline` int ,
|
|
`rent_value` DECIMAL
|
|
);
|
|
|
|
CREATE TABLE `dim_equipment` (
|
|
`equipment_id` int PRIMARY KEY,
|
|
`name` TEXT ,
|
|
`type` TEXT ,
|
|
`version` TEXT
|
|
);
|
|
|
|
CREATE TABLE `dim_store` (
|
|
`sk_store_id` int PRIMARY KEY,
|
|
`nk_store_id` int ,
|
|
`store_manager_id` int ,
|
|
`store_manager_start_date` DATE ,
|
|
`store_manager_end_date` DATE ,
|
|
`active_manager` varchar(64) ,
|
|
`store_address` varchar(64) ,
|
|
`store_address2` varchar(64) ,
|
|
`store_postal_code` varchar(64) ,
|
|
`store_city` varchar(64) ,
|
|
`store_country` varchar(64)
|
|
);
|
|
|
|
CREATE TABLE `bridge_equipment` (
|
|
`equipment_hash_DK` int PRIMARY KEY,
|
|
`id_FK` int
|
|
);
|
|
|
|
CREATE TABLE `dim_service_type` (
|
|
`service_type_id` INT PRIMARY KEY,
|
|
`service_name` varchar(64)
|
|
);
|
|
|
|
CREATE TABLE `dim_staff` (
|
|
`staff_id` int PRIMARY KEY,
|
|
`staff_full_name` varchar(64) ,
|
|
`staff_address` varchar(64) ,
|
|
`staff_city` varchar(64) ,
|
|
`staff_country` varchar(64) ,
|
|
`staff_email` varchar(64)
|
|
);
|
|
|
|
CREATE TABLE `dim_car` (
|
|
`inventory_id` int PRIMARY KEY,
|
|
`production_year` int ,
|
|
`model` varchar(64) ,
|
|
`producer` varchar(64) ,
|
|
`fuel_type` varchar(64) ,
|
|
`license_plate` varchar(64) ,
|
|
`store_id` int ,
|
|
`is_rented` varchar(64) ,
|
|
`is_sold` varchar(64)
|
|
);
|
|
|
|
ALTER TABLE `fact_service` ADD CONSTRAINT `fact_service_fk0` FOREIGN KEY (`inventory_id`) REFERENCES `dim_cars`(`inventory_id`);
|
|
|
|
ALTER TABLE `fact_service` ADD CONSTRAINT `fact_service_fk1` FOREIGN KEY (`service_date`) REFERENCES `dim_calendar`(`date_id`);
|
|
|
|
ALTER TABLE `fact_service` ADD CONSTRAINT `fact_service_fk2` FOREIGN KEY (`store_id`) REFERENCES `dim_store`(`sk_store_id`);
|
|
|
|
ALTER TABLE `fact_service` ADD CONSTRAINT `fact_service_fk3` FOREIGN KEY (`service_type_id`) REFERENCES `dim_service_type`(`service_type_id`);
|
|
|
|
ALTER TABLE `fact_rentals` ADD CONSTRAINT `fact_rentals_fk0` FOREIGN KEY (`customer_id`) REFERENCES `dim_customer`(`customer_id`);
|
|
|
|
ALTER TABLE `fact_rentals` ADD CONSTRAINT `fact_rentals_fk1` FOREIGN KEY (`store_id`) REFERENCES `dim_store`(`sk_store_id`);
|
|
|
|
ALTER TABLE `fact_rentals` ADD CONSTRAINT `fact_rentals_fk2` FOREIGN KEY (`staff_id`) REFERENCES `dim_staff`(`staff_id`);
|
|
|
|
ALTER TABLE `fact_rentals` ADD CONSTRAINT `fact_rentals_fk3` FOREIGN KEY (`inventory_id`) REFERENCES `dim_cars`(`inventory_id`);
|
|
|
|
ALTER TABLE `fact_rentals` ADD CONSTRAINT `fact_rentals_fk4` FOREIGN KEY (`equipment_hash_FK`) REFERENCES `bridge_equipment`(`equipment_hash_DK`);
|
|
|
|
ALTER TABLE `fact_rentals` ADD CONSTRAINT `fact_rentals_fk5` FOREIGN KEY (`rent_start`) REFERENCES `dim_calendar`(`date_id`);
|
|
|
|
ALTER TABLE `fact_rentals` ADD CONSTRAINT `fact_rentals_fk6` FOREIGN KEY (`rent_end`) REFERENCES `dim_calendar`(`date_id`);
|
|
|
|
ALTER TABLE `fact_rentals` ADD CONSTRAINT `fact_rentals_fk7` FOREIGN KEY (`payment_date`) REFERENCES `dim_calendar`(`date_id`);
|
|
|
|
ALTER TABLE `fact_rentals` ADD CONSTRAINT `fact_rentals_fk8` FOREIGN KEY (`payment_deadline`) REFERENCES `dim_calendar`(`date_id`);
|
|
|
|
ALTER TABLE `bridge_equipment` ADD CONSTRAINT `bridge_equipment_fk0` FOREIGN KEY (`id_FK`) REFERENCES `dim_equipment`(`equipment_id`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|