From 2bd1e23c1b6561f8f70d473f1f52f176482dedd7 Mon Sep 17 00:00:00 2001 From: Micke Nordin Date: Fri, 22 May 2020 16:32:48 +0200 Subject: [PATCH] Correct index and create if not exists --- weather.sql | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/weather.sql b/weather.sql index 75ca1b0..0aac23f 100644 --- a/weather.sql +++ b/weather.sql @@ -1,4 +1,4 @@ -CREATE TABLE `weather` ( +CREATE TABLE IF NOT EXISTS `weather` ( `observation_id` int NOT NULL AUTO_INCREMENT, `date` date DEFAULT NULL, `time` time DEFAULT NULL, @@ -6,12 +6,13 @@ CREATE TABLE `weather` ( `rel_hum` decimal(10,0) DEFAULT NULL, `temp` float DEFAULT NULL, `windspeed` float DEFAULT NULL, + `station` int DEFAULT NULL, `winddir` int DEFAULT NULL, PRIMARY KEY (`observation_id`), - UNIQUE KEY `date_time_idx` (`date`,`time`) + UNIQUE KEY `date_time_idx` (`date`,`time`,`station`) ) -CREATE TABLE `aggregated_weather` ( +CREATE TABLE IF NOT EXISTS `aggregated_weather` ( `Date_id` int NOT NULL AUTO_INCREMENT, `Date` date DEFAULT NULL, `T_max` float DEFAULT NULL, @@ -22,6 +23,7 @@ CREATE TABLE `aggregated_weather` ( `RH_mean` float DEFAULT NULL, `Rainfall` float DEFAULT NULL, `ETo` float DEFAULT NULL, + `station` int DEFAULT NULL, PRIMARY KEY (`Date_id`), - UNIQUE KEY `date_idx` (`Date`) + UNIQUE KEY `date_idx` (`Date`,`station`) )