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



CREATE TABLE sensorkaroline (
  idsensorkaroline INTEGER UNSIGNED  NOT NULL   AUTO_INCREMENT,
  nome VARCHAR(45)  NULL  ,
  ativo BOOL  NULL DEFAULT 1 ,
  limite INTEGER UNSIGNED  NULL DEFAULT 100 ,
  contador INTEGER UNSIGNED  NULL DEFAULT 0 ,
  unidade VARCHAR(10)  NULL  ,
  sigla VARCHAR(3)  NULL    ,
PRIMARY KEY(idsensorkaroline));



CREATE TABLE coletorkaroline (
  idcoletorkaroline INTEGER UNSIGNED  NOT NULL   AUTO_INCREMENT,
  nome VARCHAR(45)  NULL  ,
  contador INTEGER UNSIGNED  NULL DEFAULT 0 ,
  ativo BOOL  NULL DEFAULT 1 ,
  limite INTEGER UNSIGNED  NULL DEFAULT 100   ,
PRIMARY KEY(idcoletorkaroline));



CREATE TABLE leiturakaroline (
  idleiturakaroline INTEGER UNSIGNED  NOT NULL   AUTO_INCREMENT,
  sensorkaroline_idsensorkaroline INTEGER UNSIGNED  NOT NULL  ,
  coletorkaroline_idcoletorKaroline INTEGER UNSIGNED  NOT NULL  ,
  mackaroline_idmacKaroline VARCHAR(17)  NOT NULL  ,
  dataleitura DATE  NULL  ,
  horaleitura TIME  NULL  ,
  valor INTEGER UNSIGNED  NULL    ,
PRIMARY KEY(idleiturakaroline)  ,
INDEX leitura_FKIndex1(mackaroline_idmacKaroline)  ,
INDEX leitura_FKIndex2(sensorkaroline_idsensorkaroline)  ,
INDEX leitura_FKIndex3(coletorkaroline_idcoletorKaroline),
  FOREIGN KEY(mackaroline_idmacKaroline)
    REFERENCES mackaroline(idmacKaroline)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
  FOREIGN KEY(sensorkaroline_idsensorkaroline)
    REFERENCES sensorkaroline(idsensorkaroline)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
  FOREIGN KEY(coletorkaroline_idcoletorKaroline)
    REFERENCES coletorkaroline(idcoletorKaroline)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION);




