Re: Looking for elegant solution to sensor / reading / alert database design.
Date: Tue, 7 Dec 2010 10:42:30 -0800 (PST)
Message-ID: <890bd65d-84b9-4820-b693-8b4921c36923_at_z17g2000prz.googlegroups.com>
Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Please learn to follow ISO-11179 data element naming conventions and formatting rules. The singular table names (they are sets of more than one element, aren't they?) so use a collective or plural name and the use of universal "_id" on every table were pretty bad.
\Sample data is also a good idea, along with clear specifications. It is very hard to debug code when you do not let us see it. If you want to learn how to ask a question on a Newsgroup, look at: http://www.catb.org/~esr/faqs/smart-questions.html
There can be many locations.
An alert is an entity that must be acknowledged, acted upon, etc.
Initially I related readings to alerts like this (very cut down) : -
CREATE TABLE Locations
Now you start making mistakes. The location of a sensor is NOT an
Each locations can have 0 or many sensors.
Each sensor can have many readings.
A sensor is either in "alert" state or "normal" state depending on
the
last reading.
(location_id CHAR(16) NOT NULL PRIMARY KEY); --htm number?
sensor_status CHAR(6) NOT NULL
GENERATED ALWAYS AS (CASE WHEN reading_value > 42 --whatever the rule is THEN 'alert' ELSE 'normal' END)Received on Tue Dec 07 2010 - 19:42:30 CET