-- phpMyAdmin SQL Dump
-- version 5.2.1
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Tempo de geração: 12/06/2026 às 20:19
-- Versão do servidor: 10.4.32-MariaDB
-- Versão do PHP: 8.2.12

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: `provafinalarthur`
--

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

--
-- Estrutura para tabela `coletorarthur`
--

CREATE TABLE `coletorarthur` (
  `idcoletorArthur` int(10) UNSIGNED NOT NULL,
  `nome` varchar(45) DEFAULT NULL,
  `contador` int(10) UNSIGNED DEFAULT 0,
  `ativo` tinyint(1) DEFAULT 1,
  `limite` int(10) UNSIGNED DEFAULT 100
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Despejando dados para a tabela `coletorarthur`
--

INSERT INTO `coletorarthur` (`idcoletorArthur`, `nome`, `contador`, `ativo`, `limite`) VALUES
(1, 'ColetorTeste', 1, 1, 100);

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

--
-- Estrutura para tabela `leituraarthur`
--

CREATE TABLE `leituraarthur` (
  `idleituraArthur` int(10) UNSIGNED NOT NULL,
  `sensorArthur_idsensorArthur` int(10) UNSIGNED NOT NULL,
  `coletorArthur_idcoletorArthur` int(10) UNSIGNED NOT NULL,
  `macArthur_idmacArthur` varchar(17) NOT NULL,
  `dataleitura` date DEFAULT NULL,
  `horaleitura` time DEFAULT NULL,
  `valor` int(10) UNSIGNED DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Despejando dados para a tabela `leituraarthur`
--

INSERT INTO `leituraarthur` (`idleituraArthur`, `sensorArthur_idsensorArthur`, `coletorArthur_idcoletorArthur`, `macArthur_idmacArthur`, `dataleitura`, `horaleitura`, `valor`) VALUES
(2, 1, 1, '', '2026-06-02', '14:21:55', 123);

--
-- Acionadores `leituraarthur`
--
DELIMITER $$
CREATE TRIGGER `tgdeleteleituraArthur_coletor` AFTER DELETE ON `leituraarthur` FOR EACH ROW BEGIN
  UPDATE coletorArthur
  SET contador = contador + 1
  WHERE idcoletorArthur = OLD.coletorArthur_idcoletorArthur;
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tgdeleteleituraArthur_mac` AFTER DELETE ON `leituraarthur` FOR EACH ROW BEGIN
  UPDATE macArthur
  SET contador = contador + 1
  WHERE idmacArthur = OLD.macArthur_idmacArthur;
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tgdeleteleituraArthur_sensor` AFTER DELETE ON `leituraarthur` FOR EACH ROW BEGIN
  UPDATE sensorArthur
  SET contador = contador + 1
  WHERE idsensorArthur = OLD.sensorArthur_idsensorArthur;
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tginsertleituraArthur_coletor` AFTER INSERT ON `leituraarthur` FOR EACH ROW BEGIN
  UPDATE coletorArthur
  SET contador = contador + 1
  WHERE idcoletorArthur = NEW.coletorArthur_idcoletorArthur;
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tginsertleituraArthur_mac` AFTER INSERT ON `leituraarthur` FOR EACH ROW BEGIN
  UPDATE macArthur
  SET contador = contador + 1
  WHERE idmacArthur = NEW.macArthur_idmacArthur;
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tginsertleituraArthur_sensor` AFTER INSERT ON `leituraarthur` FOR EACH ROW BEGIN
  UPDATE sensorArthur
  SET contador = contador + 1
  WHERE idsensorArthur = NEW.sensorArthur_idsensorArthur;
END
$$
DELIMITER ;

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

--
-- Estrutura para tabela `macarthur`
--

CREATE TABLE `macarthur` (
  `idmacArthur` varchar(17) NOT NULL,
  `nome` varchar(45) DEFAULT NULL,
  `contador` int(10) UNSIGNED DEFAULT 0,
  `ativo` tinyint(1) DEFAULT 1,
  `limite` int(10) UNSIGNED DEFAULT 100
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Despejando dados para a tabela `macarthur`
--

INSERT INTO `macarthur` (`idmacArthur`, `nome`, `contador`, `ativo`, `limite`) VALUES
('', 'Macteste', 1, 1, 100);

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

--
-- Estrutura para tabela `sensorarthur`
--

CREATE TABLE `sensorarthur` (
  `idsensorArthur` int(10) UNSIGNED NOT NULL,
  `nome` varchar(45) DEFAULT NULL,
  `ativo` tinyint(1) DEFAULT 1,
  `limite` int(10) UNSIGNED DEFAULT 100,
  `contador` int(10) UNSIGNED DEFAULT 0,
  `unidade` varchar(10) DEFAULT NULL,
  `sigla` varchar(3) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Despejando dados para a tabela `sensorarthur`
--

INSERT INTO `sensorarthur` (`idsensorArthur`, `nome`, `ativo`, `limite`, `contador`, `unidade`, `sigla`) VALUES
(1, 'Sensorteste', 1, 100, 1, '1234', 'a');

--
-- Índices para tabelas despejadas
--

--
-- Índices de tabela `coletorarthur`
--
ALTER TABLE `coletorarthur`
  ADD PRIMARY KEY (`idcoletorArthur`);

--
-- Índices de tabela `leituraarthur`
--
ALTER TABLE `leituraarthur`
  ADD PRIMARY KEY (`idleituraArthur`),
  ADD KEY `leitura_FKIndex1` (`macArthur_idmacArthur`),
  ADD KEY `leitura_FKIndex2` (`sensorArthur_idsensorArthur`),
  ADD KEY `leitura_FKIndex3` (`coletorArthur_idcoletorArthur`);

--
-- Índices de tabela `macarthur`
--
ALTER TABLE `macarthur`
  ADD PRIMARY KEY (`idmacArthur`);

--
-- Índices de tabela `sensorarthur`
--
ALTER TABLE `sensorarthur`
  ADD PRIMARY KEY (`idsensorArthur`);

--
-- AUTO_INCREMENT para tabelas despejadas
--

--
-- AUTO_INCREMENT de tabela `coletorarthur`
--
ALTER TABLE `coletorarthur`
  MODIFY `idcoletorArthur` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

--
-- AUTO_INCREMENT de tabela `leituraarthur`
--
ALTER TABLE `leituraarthur`
  MODIFY `idleituraArthur` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;

--
-- AUTO_INCREMENT de tabela `sensorarthur`
--
ALTER TABLE `sensorarthur`
  MODIFY `idsensorArthur` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

--
-- Restrições para tabelas despejadas
--

--
-- Restrições para tabelas `leituraarthur`
--
ALTER TABLE `leituraarthur`
  ADD CONSTRAINT `leituraarthur_ibfk_1` FOREIGN KEY (`macArthur_idmacArthur`) REFERENCES `macarthur` (`idmacArthur`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `leituraarthur_ibfk_2` FOREIGN KEY (`sensorArthur_idsensorArthur`) REFERENCES `sensorarthur` (`idsensorArthur`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `leituraarthur_ibfk_3` FOREIGN KEY (`coletorArthur_idcoletorArthur`) REFERENCES `coletorarthur` (`idcoletorArthur`) 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 */;
