CREATE TABLE sensormiguel (
  idsensormiguel INTEGER UNSIGNED  NOT NULL   AUTO_INCREMENT,
  nome VARCHAR(45)  NULL  ,
  contador INTEGER UNSIGNED  NULL DEFAULT 0   ,
PRIMARY KEY(idsensormiguel));



CREATE TABLE macmiguel (
  idmacmiguel VARCHAR(17)  NOT NULL  ,
  nome VARCHAR(45)  NULL  ,
  ativo BOOL  NULL DEFAULT 1 ,
  contador INTEGER UNSIGNED  NULL DEFAULT 0 ,
  limite INTEGER UNSIGNED  NULL DEFAULT 100   ,
PRIMARY KEY(idmacmiguel));



CREATE TABLE leituramiguel (
  idleituramiguel INTEGER UNSIGNED  NOT NULL   AUTO_INCREMENT,
  sensormiguel_idsensormiguel INTEGER UNSIGNED  NOT NULL  ,
  macmiguel_idmacmiguel VARCHAR(17)  NOT NULL  ,
  dataleitura DATE  NULL  ,
  horaleitura TIME  NULL  ,
  valor REAL  NULL    ,
PRIMARY KEY(idleituramiguel)  ,
INDEX leituramiguel_FKIndex1(macmiguel_idmacmiguel)  ,
INDEX leituramiguel_FKIndex2(sensormiguel_idsensormiguel),
  FOREIGN KEY(macmiguel_idmacmiguel)
    REFERENCES macmiguel(idmacmiguel)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
  FOREIGN KEY(sensormiguel_idsensormiguel)
    REFERENCES sensormiguel(idsensormiguel)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION);




