CREATE TABLE macpam (
  idmacpam 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(idmacpam));



CREATE TABLE sensorpam (
  idsensorpam 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(idsensorpam));



CREATE TABLE coletorpam (
  idcoletorpam 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(idcoletorpam));



CREATE TABLE leiturapam (
  idleiturapam INTEGER UNSIGNED  NOT NULL   AUTO_INCREMENT,
  sensorpam_idsensorpam INTEGER UNSIGNED  NOT NULL  ,
  coletorpam_idcoletorpam INTEGER UNSIGNED  NOT NULL  ,
  macpam_idmacpam VARCHAR(17)  NOT NULL  ,
  dataleitura DATE  NULL  ,
  horaleitura TIME  NULL  ,
  valor INTEGER UNSIGNED ZEROFILL  NULL    ,
PRIMARY KEY(idleiturapam)  ,
INDEX leiturapam_FKIndex3(macpam_idmacpam)  ,
INDEX leiturapam_FKIndex3(coletorpam_idcoletorpam)  ,
INDEX leiturapam_FKIndex3(sensorpam_idsensorpam),
  FOREIGN KEY(macpam_idmacpam)
    REFERENCES macpam(idmacpam)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
  FOREIGN KEY(coletorpam_idcoletorpam)
    REFERENCES coletorpam(idcoletorpam)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
  FOREIGN KEY(sensorpam_idsensorpam)
    REFERENCES sensorpam(idsensorpam)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION);




