CREATE TABLE ip_addresses ( id INTEGER PRIMARY KEY AUTO_INCREMENT, string VARCHAR(15), UNIQUE(string) ) Type=InnoDB; CREATE TABLE devices ( id INTEGER PRIMARY KEY AUTO_INCREMENT, name VARCHAR(255), mac_address VARCHAR(17), ip_static_id INTEGER, FOREIGN KEY (ip_static_id) REFERENCES ip_addresses(id), INDEX(ip_static_id), UNIQUE(mac_address) ) Type=InnoDB; CREATE TABLE activity ( id INTEGER PRIMARY KEY AUTO_INCREMENT, minute DATETIME, counter BIGINT, device_id INTEGER NOT NULL, ip_address_id INTEGER NOT NULL, FOREIGN KEY (device_id) REFERENCES devices(id), FOREIGN KEY (ip_address_id) REFERENCES ip_addresses(id), INDEX(device_id), INDEX(ip_address_id) ) Type=InnoDB;