-- phpMyAdmin SQL Dump
-- version 5.2.0
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Tempo de geração: 10-Jun-2025 às 22:05
-- Versão do servidor: 10.4.27-MariaDB
-- versão do PHP: 8.0.25

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Banco de dados: `bancoesplucasp`
--

-- --------------------------------------------------------

--
-- Estrutura da tabela `leituralpgd`
--

CREATE TABLE `leituralpgd` (
  `idleituralpgd` int(10) UNSIGNED NOT NULL,
  `maclpgd_idmaclpgd` varchar(17) NOT NULL,
  `dataleitura` date DEFAULT NULL,
  `valor` double DEFAULT NULL,
  `horaleitura` time DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

--
-- Acionadores `leituralpgd`
--
DELIMITER $$
CREATE TRIGGER `tgdeleteleituralpgd` AFTER DELETE ON `leituralpgd` FOR EACH ROW BEGIN
UPDATE maclpgd
SET contador=contador-1
where idmaclpgd=old.maclpgd_idmaclpgd;


END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tginsertleituralpgd` AFTER INSERT ON `leituralpgd` FOR EACH ROW BEGIN
UPDATE maclpgd
SET contador=contador+1
where idmaclpgd=new.maclpgd_idmaclpgd;
END
$$
DELIMITER ;

-- --------------------------------------------------------

--
-- Estrutura da tabela `maclpgd`
--

CREATE TABLE `maclpgd` (
  `idmaclpgd` varchar(17) NOT NULL,
  `nome` varchar(34) DEFAULT NULL,
  `contador` int(10) UNSIGNED DEFAULT 0,
  `ativo` tinyint(1) DEFAULT 1
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

--
-- Índices para tabelas despejadas
--

--
-- Índices para tabela `leituralpgd`
--
ALTER TABLE `leituralpgd`
  ADD PRIMARY KEY (`idleituralpgd`),
  ADD KEY `leituralpgd_FKIndex1` (`maclpgd_idmaclpgd`);

--
-- Índices para tabela `maclpgd`
--
ALTER TABLE `maclpgd`
  ADD PRIMARY KEY (`idmaclpgd`);

--
-- AUTO_INCREMENT de tabelas despejadas
--

--
-- AUTO_INCREMENT de tabela `leituralpgd`
--
ALTER TABLE `leituralpgd`
  MODIFY `idleituralpgd` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- Restrições para despejos de tabelas
--

--
-- Limitadores para a tabela `leituralpgd`
--
ALTER TABLE `leituralpgd`
  ADD CONSTRAINT `leituralpgd_ibfk_1` FOREIGN KEY (`maclpgd_idmaclpgd`) REFERENCES `maclpgd` (`idmaclpgd`) ON DELETE NO ACTION ON UPDATE NO ACTION;
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
