Skip to content
Snippets Groups Projects
Commit 9de3f917 authored by PatrickMurphy99's avatar PatrickMurphy99
Browse files

remade tables

Remade tables as discussed, changed some types around, made the population tables
parent 64908d94
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
data/Covid19_Schema_Design.png

185 KiB

......@@ -6,40 +6,25 @@ CREATE TABLE Countries(
country_name VARCHAR(128) UNIQUE NOT NULL
);
-- each region has a unique region code and unique name
-- no nulls
-- region codes are used in the rest of the tables as keys
CREATE TABLE Regions(
region_code VARCHAR(5) PRIMARY KEY,
region_name VARCHAR(128) UNIQUE NOT NULL
);
-- encaptures data about the region
-- longittude and latitude specify certain part of the region
CREATE TABLE Regions_Information(
region_code VARCHAR(5) PRIMARY KEY,
CREATE TABLE Regions(
region_code BIGINT IDENTITY(1, 1) PRIMARY KEY,
region_name VARCHAR(128) NOT NULL,
country_code VARCHAR(2) NOT NULL,
longitude FLOAT NULL,
latitude FLOAT NULL,
FOREIGN KEY (region_code) REFERENCES Regions(region_code),
FOREIGN KEY (country_code) REFERENCES Countries(country_code)
);
-- each distict has a unique district code and name
-- district codes are primary keys
CREATE TABLE Districts(
district_code VARCHAR(8) PRIMARY KEY,
district_name VARCHAR(128) UNIQUE NOT NULL
);
-- information of the location of the district
-- longitude and latitude specify certain part of the district
CREATE TABLE Districts_Information(
district_code VARCHAR(8) PRIMARY KEY,
CREATE TABLE Districts(
district_code BIGINT IDENTITY(1, 1) PRIMARY KEY,
district_name VARCHAR(128) NOT NULL,
region_code VARCHAR(5) NOT NULL,
longitude FLOAT NULL,
latitude FLOAT NULL,
FOREIGN KEY (district_code) REFERENCES Districts(district_code),
FOREIGN KEY (region_code) REFERENCES Regions(region_code)
);
......@@ -47,8 +32,8 @@ CREATE TABLE Districts_Information(
-- source ID is autogenerated
-- source info is unique
CREATE TABLE Sources(
source_id INT IDENTITY(1, 1) PRIMARY KEY,
source_informatoin VARCHAR(256) UNIQUE NOT NULL
source_id BIGINT IDENTITY(1, 1) PRIMARY KEY,
source_information VARCHAR(256) UNIQUE NOT NULL
);
-- information on cases, recovery numbers, and deaths
......@@ -56,7 +41,7 @@ CREATE TABLE Sources(
CREATE TABLE Cases_Per_Country(
country_code VARCHAR(2) PRIMARY KEY,
date_collected DATETIME2 NOT NULL,
source_id INT NOT NULL,
source_id BIGINT NOT NULL,
death_numbers INT NULL,
case_numbers INT NULL,
recovery_numbers INT NULL,
......@@ -67,9 +52,9 @@ CREATE TABLE Cases_Per_Country(
-- information on cases, recovery numbers, and deaths
-- per region
CREATE TABLE Cases_Per_Region(
region_code VARCHAR(5) PRIMARY KEY,
region_code BIGINT PRIMARY KEY,
date_collected DATETIME2 NOT NULL,
source_id INT NOT NULL,
source_id BIGINT NOT NULL,
death_numbers INT NULL,
case_numbers INT NULL,
recovery_numbers INT NULL,
......@@ -80,9 +65,9 @@ CREATE TABLE Cases_Per_Region(
-- information on cases, recovery numbers, and deaths
-- per district
CREATE TABLE Cases_Per_District(
district_code VARCHAR(8) PRIMARY KEY,
district_code BIGINT PRIMARY KEY,
date_collected DATETIME2 NOT NULL,
source_id INT NOT NULL,
source_id BIGINT NOT NULL,
death_numbers INT NULL,
case_numbers INT NULL,
recovery_numbers INT NULL,
......@@ -94,7 +79,7 @@ CREATE TABLE Cases_Per_District(
CREATE TABLE Vaccinations_Per_Country(
vaccination_rate INT NOT NULL,
country_code VARCHAR(2) PRIMARY KEY,
source_id INT NOT NULL,
source_id BIGINT NOT NULL,
FOREIGN KEY (country_code) REFERENCES Countries(country_code),
FOREIGN KEY (source_id) REFERENCES Sources(source_id)
);
......@@ -102,8 +87,8 @@ CREATE TABLE Vaccinations_Per_Country(
-- keeps track of vaccinations per Region
CREATE TABLE Vaccinations_Per_Region(
vaccination_rate INT NOT NULL,
region_code VARCHAR(5) PRIMARY KEY,
source_id INT NOT NULL,
region_code BIGINT PRIMARY KEY,
source_id BIGINT NOT NULL,
FOREIGN KEY (region_code) REFERENCES Regions(region_code),
FOREIGN KEY (source_id) REFERENCES Sources(source_id)
);
......@@ -111,8 +96,8 @@ CREATE TABLE Vaccinations_Per_Region(
-- keeps track of vaccinations per District
CREATE TABLE Vaccinations_Per_District(
vaccination_rate INT NOT NULL,
district_code VARCHAR(8) PRIMARY KEY,
source_id INT NOT NULL,
district_code BIGINT PRIMARY KEY,
source_id BIGINT NOT NULL,
FOREIGN KEY (district_code) REFERENCES Districts(district_code),
FOREIGN KEY (source_id) REFERENCES Sources(source_id)
);
......@@ -120,7 +105,7 @@ CREATE TABLE Vaccinations_Per_District(
-- keeps track of strain data per country
CREATE TABLE Strains_Per_Country(
country_code VARCHAR(2) PRIMARY KEY,
source_id INT NOT NULL,
source_id BIGINT NOT NULL,
alpha_rate INT NULL,
beta_rate INT NULL,
gamma_rate INT NULL,
......@@ -132,7 +117,7 @@ CREATE TABLE Strains_Per_Country(
-- keeps track of strain data per region
CREATE TABLE Strains_Per_Region(
region_code VARCHAR(5) PRIMARY KEY,
region_code BIGINT PRIMARY KEY,
source_id INT NOT NULL,
alpha_rate INT NULL,
beta_rate INT NULL,
......@@ -145,7 +130,7 @@ CREATE TABLE Strains_Per_Region(
-- keeps track of strain data per district
CREATE TABLE Strains_Per_District(
district_code VARCHAR(8) PRIMARY KEY,
district_code BIGINT PRIMARY KEY,
source_id INT NOT NULL,
alpha_rate INT NULL,
beta_rate INT NULL,
......@@ -159,7 +144,7 @@ CREATE TABLE Strains_Per_District(
-- age related data on covid per country
CREATE TABLE Age_Per_Country(
country_id VARCHAR(2) PRIMARY KEY,
source_id INT NOT NULL,
source_id BIGINT NOT NULL,
age_group VARCHAR(64) NOT NULL,
case_number INT NULL,
recovery_number INT NULL,
......@@ -175,8 +160,8 @@ CREATE TABLE Age_Per_Country(
-- age related data on covid per region
CREATE TABLE Age_Per_Region(
region_id VARCHAR(5) PRIMARY KEY,
source_id INT NOT NULL,
region_id BIGINT PRIMARY KEY,
source_id BIGINT NOT NULL,
age_group VARCHAR(64) NOT NULL,
case_number INT NULL,
recovery_number INT NULL,
......@@ -192,8 +177,8 @@ CREATE TABLE Age_Per_Region(
-- age related data on covid per district
CREATE TABLE Age_Per_District(
district_id VARCHAR(8) PRIMARY KEY,
source_id INT NOT NULL,
district_id BIGINT PRIMARY KEY,
source_id BIGINT NOT NULL,
age_group VARCHAR(64) NOT NULL,
case_number INT NULL,
recovery_number INT NULL,
......@@ -205,4 +190,28 @@ CREATE TABLE Age_Per_District(
death_rate INT NULL,
FOREIGN KEY (district_id) REFERENCES Districts(district_code),
FOREIGN KEY (source_id) REFERENCES Sources(source_id)
);
-- population per country on a given date
CREATE TABLE Population_Per_Country(
country_code VARCHAR(2) PRIMARY KEY,
population_amount BIGINT NOT NULL,
date_collected DATETIME2 NOT NULL,
FOREIGN KEY (country_code) REFERENCES Countries(country_code)
);
-- population per region on a given date
CREATE TABLE Population_Per_Region(
region_code BIGINT PRIMARY KEY,
population_amount BIGINT NOT NULL,
date_collected DATETIME2 NOT NULL,
FOREIGN KEY (region_code) REFERENCES Regions(region_code)
);
-- population per district on a given date
CREATE TABLE Population_Per_District(
district_code BIGINT PRIMARY KEY,
population_amount BIGINT NOT NULL,
date_collected DATETIME2 NOT NULL,
FOREIGN KEY (district_code) REFERENCES Districts(district_code)
);
\ No newline at end of file
data/Schema482.png

179 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment