-- version 4.7.5
-- https://www.phpmyadmin.net/
--
-- Host: localhost
-- Generation Time: Nov 25, 2019 at 07:12 PM
-- Server version: 5.6.34
-- PHP Version: 7.1.11
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";
--
-- Database: `sistema`
--
-- --------------------------------------------------------
--
-- Table structure for table `passwords`
--
CREATE TABLE `passwords` (
`id` int(11) NOT NULL,
`psw` varchar(100) NOT NULL,
`idUser` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Dumping data for table `passwords`
--
INSERT INTO `passwords` (`id`, `psw`, `idUser`) VALUES
(1, '123', 1),
(2, '456', 1),
(3, '789', 2),
(4, '987', 3),
(5, '654', 3),
(6, '321', 4),
(7, '555', 2);
-- --------------------------------------------------------
--
-- Table structure for table `users`
--
CREATE TABLE `users` (
`id` int(11) NOT NULL,
`username` varchar(100) NOT NULL,
`estado` tinyint(1) NOT NULL DEFAULT '0',
`dataReg` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Dumping data for table `users`
--
INSERT INTO `users` (`id`, `username`, `estado`, `dataReg`) VALUES
(1, 'marco@mail.pt', 0, '2019-11-19 21:52:03'),
(2, 'marcelo@mail.pt', 0, '2019-11-19 21:52:03'),
(3, 'ze@mail.pt', 0, '2019-11-19 21:52:24'),
(4, 'telma@mail.pt', 0, '2019-11-19 21:52:37');
-- --------------------------------------------------------
--
-- Stand-in structure for view `v1_passwords`
-- (See below for the actual view)
--
CREATE TABLE `v1_passwords` (
`id` int(11)
,`psw` varchar(100)
,`idUser` int(11)
);
-- --------------------------------------------------------
--
-- Structure for view `v1_passwords`
--
DROP TABLE IF EXISTS `v1_passwords`;
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1_passwords` AS select `passwords`.`id` AS `id`,`passwords`.`psw` AS `psw`,`passwords`.`idUser` AS `idUser` from `passwords` where `passwords`.`id` in (select max(`passwords`.`id`) from `passwords` group by `passwords`.`idUser`) ;
--
-- Indexes for dumped tables
--
--
-- Indexes for table `passwords`
--
ALTER TABLE `passwords`
ADD PRIMARY KEY (`id`),
ADD KEY `idUser` (`idUser`);
--
-- Indexes for table `users`
--
ALTER TABLE `users`
ADD PRIMARY KEY (`id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `passwords`
--
ALTER TABLE `passwords`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=8;
--
-- AUTO_INCREMENT for table `users`
--
ALTER TABLE `users`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;
--
-- Constraints for dumped tables
--
--
-- Constraints for table `passwords`
--
ALTER TABLE `passwords`
ADD CONSTRAINT `passwords_ibfk_1` FOREIGN KEY (`idUser`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
COMMIT;
https://www.w3schools.com/quiztest/quiztest.asp?qtest=MATH
ResponderEliminar