-- version 4.7.5
-- https://www.phpmyadmin.net/
--
-- Host: localhost
-- Generation Time: Nov 27, 2019 at 01:59 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,
`pass` varchar(100) NOT NULL,
`idUser` int(11) NOT NULL,
`estadoReg` tinyint(1) NOT NULL DEFAULT '1',
`dataReg` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Dumping data for table `passwords`
--
INSERT INTO `passwords` (`id`, `pass`, `idUser`, `estadoReg`, `dataReg`) VALUES
(1, '123', 1, 1, '2019-11-19 15:24:26'),
(2, '321', 1, 1, '2019-11-19 15:24:26'),
(3, '987', 2, 1, '2019-11-19 15:24:56'),
(4, '654', 3, 1, '2019-11-19 15:24:56'),
(5, '765', 3, 1, '2019-11-19 15:28:37'),
(6, '991', 1, 1, '2019-11-19 15:28:37'),
(7, '0000', 2, 1, '2019-11-19 15:44:55');
-- --------------------------------------------------------
--
-- Table structure for table `users`
--
CREATE TABLE `users` (
`id` int(11) NOT NULL,
`username` varchar(100) NOT NULL,
`estadoReg` tinyint(1) NOT NULL DEFAULT '0',
`dataReg` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Dumping data for table `users`
--
INSERT INTO `users` (`id`, `username`, `estadoReg`, `dataReg`) VALUES
(1, 'mloureiro', 0, '2019-11-19 15:09:27'),
(2, 'diogo', 0, '2019-11-19 15:09:27'),
(3, 'ana', 0, '2019-11-19 15:09:36');
-- --------------------------------------------------------
--
-- Stand-in structure for view `v1_passwords`
-- (See below for the actual view)
--
CREATE TABLE `v1_passwords` (
`id` int(11)
,`idUser` int(11)
,`pass` varchar(100)
);
-- --------------------------------------------------------
--
-- Stand-in structure for view `v2_users_passwords`
-- (See below for the actual view)
--
CREATE TABLE `v2_users_passwords` (
`idUser` int(11)
,`username` varchar(100)
,`estadoReg` tinyint(1)
,`pass` varchar(100)
);
-- --------------------------------------------------------
--
-- 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`.`idUser` AS `idUser`,`passwords`.`pass` AS `pass` from `passwords` where `passwords`.`id` in (select max(`passwords`.`id`) from `passwords` group by `passwords`.`idUser`) ;
-- --------------------------------------------------------
--
-- Structure for view `v2_users_passwords`
--
DROP TABLE IF EXISTS `v2_users_passwords`;
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2_users_passwords` AS select `v1_passwords`.`idUser` AS `idUser`,`users`.`username` AS `username`,`users`.`estadoReg` AS `estadoReg`,`v1_passwords`.`pass` AS `pass` from (`users` join `v1_passwords`) where (`users`.`id` = `v1_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=4;
--
-- 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;
v1_Admin
SELECT username,privilegio FROM users,privilegios,users_privilegios WHERE users.id=idUser AND privilegios.id=idPrivilegio AND idPrivilegio=1
Sem comentários:
Enviar um comentário