CREATE TABLE Sensor (
  idSensor INTEGER UNSIGNED  NOT NULL   AUTO_INCREMENT,
  Nome VARCHAR(15)  NULL  ,
  Contador INTEGER UNSIGNED  NULL DEFAULT 0   ,
PRIMARY KEY(idSensor));



CREATE TABLE Usuario (
  idUsuario INTEGER UNSIGNED  NOT NULL   AUTO_INCREMENT,
  Login VARCHAR(25)  NULL  ,
  Nome VARCHAR(50)  NULL  ,
  Senha VARCHAR(15)  NULL    ,
PRIMARY KEY(idUsuario));



CREATE TABLE Mac (
  idMac VARCHAR(17)  NOT NULL  ,
  Nome VARCHAR(35)  NULL  ,
  Contador INTEGER UNSIGNED  NULL DEFAULT 0   ,
PRIMARY KEY(idMac));



CREATE TABLE LeituraDaJu (
  idLeituraDaJu INTEGER UNSIGNED  NOT NULL   AUTO_INCREMENT,
  Sensor_idSensor INTEGER UNSIGNED  NOT NULL  ,
  Mac_idMac VARCHAR(17)  NOT NULL  ,
  DataLeitura DATE  NULL  ,
  HoraLeitura TEXT  NULL  ,
  ValorSensor REAL  NULL    ,
PRIMARY KEY(idLeituraDaJu)  ,
INDEX LeituraDaJu_FKIndex1(Mac_idMac)  ,
INDEX LeituraDaJu_FKIndex2(Sensor_idSensor),
  FOREIGN KEY(Mac_idMac)
    REFERENCES Mac(idMac)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
  FOREIGN KEY(Sensor_idSensor)
    REFERENCES Sensor(idSensor)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION);




