CREATE TABLE mackarol (
  idmackarol 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(idmackarol));



CREATE TABLE sensorkarol (
  idsensorkarol 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(idsensorkarol));



CREATE TABLE coletorkarol (
  idcoletorkarol 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(idcoletorkarol));



CREATE TABLE leiturakarol (
  idleiturakarol INTEGER UNSIGNED  NOT NULL   AUTO_INCREMENT,
  sensorkarol_idsensorkarol INTEGER UNSIGNED  NOT NULL  ,
  mackarol_idmackarol VARCHAR(17)  NOT NULL  ,
  coletorkarol_idcoletorkarol INTEGER UNSIGNED  NOT NULL  ,
  dataleitura DATE  NULL  ,
  horaleitura TIME  NULL  ,
  valor INTEGER UNSIGNED  NULL    ,
PRIMARY KEY(idleiturakarol)  ,
INDEX leitura_FKIndex1(mackarol_idmackarol)  ,
INDEX leitura_FKIndex2(sensorkarol_idsensorkarol)  ,
INDEX leitura_FKIndex3(coletorkarol_idcoletorkarol),
  FOREIGN KEY(mackarol_idmackarol)
    REFERENCES mackarol(idmackarol)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
  FOREIGN KEY(sensorkarol_idsensorkarol)
    REFERENCES sensorkarol(idsensorkarol)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
  FOREIGN KEY(coletorkarol_idcoletorkarol)
    REFERENCES coletorkarol(idcoletorkarol)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION);




