123456789101112131415161718192021222324252627282930313233343536373839 |
- CREATE TABLE IF NOT EXISTS var_type (
- slabel CHAR(1) UNIQUE PRIMARY KEY,
- label VARCHAR(10) UNIQUE,
- type VARCHAR(10) NOT NULL,
- start_address INT NOT NULL DEFAULT 0,
- end_address INT NOT NULL DEFAULT 250
- );
-
- CREATE TABLE IF NOT EXISTS variable (
- type CHAR(1) NOT NULL,
- address INT NOT NULL,
- unit VARCHAR(5) NULL,
- last_update DATE NULL,
-
-
- FOREIGN KEY (type) REFERENCES var_type(slabel)
- ON DELETE CASCADE,
- PRIMARY KEY(type, address)
- );
-
- CREATE TABLE IF NOT EXISTS var_value (
- type CHAR(1) NOT NULL,
- address INT NOT NULL,
- time DATE DEFAULT CURRENT_TIMESTAMP,
- value INT NOT NULL,
-
- FOREIGN KEY (type) REFERENCES variable(type)
- ON DELETE CASCADE,
- FOREIGN KEY (address) REFERENCES variable(address)
- ON DELETE CASCADE,
- PRIMARY KEY(type, address, time)
- );
-
- INSERT INTO var_type (slabel, label, type, start_address, end_address) VALUES (
- 'A', 'Analog', 'float', 1, 500);
- INSERT INTO var_type (slabel, label, type, start_address, end_address) VALUES (
- 'I', 'Integer', 'int', 5002, 6252);
- INSERT INTO var_type (slabel, label, type, start_address, end_address) VALUES (
- 'D', 'Digital', 'boolean', 1, 1000);
|