CREATE DATABASE thermometer;

USE thermometer;

CREATE TABLE nodes 
	(node_id int not null auto_increment,
	 node_name VARCHAR(64) not null,
	 node_description VARCHAR(255),
	 primary key (node_id));

CREATE TABLE alarm
	(alarm_nodeid int not null references nodes(node_id),
	 alarm_sensorid int not null,
	 alarm_type int not null,
	 alarm_text VARCHAR(128),
	 alarm_time timestamp not null,
         primary key (alarm_nodeid, alarm_sensorid, alarm_type, alarm_time));

CREATE TABLE data
	(data_sensorid int not null,
	 data_nodeid int not null references nodes(node_id),
         data_time timestamp not null,
         data_temp float not null,
         primary key (data_sensorid, data_nodeid, data_time));

