-- phpMyAdmin SQL Dump
-- version 4.0.4.1
-- http://www.phpmyadmin.net
--
-- Servidor: 127.0.0.1
-- Tiempo de generación: 20-06-2014 a las 12:24:47
-- Versión del servidor: 5.5.32
-- Versión de PHP: 5.4.19

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
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 utf8 */;

--
-- Base de datos: `prueba`
--
CREATE DATABASE IF NOT EXISTS `prueba` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
USE `prueba`;

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

--
-- Estructura de tabla para la tabla `datos_mochila`
--

CREATE TABLE IF NOT EXISTS `datos_mochila` (
  `nickname` varchar(100) NOT NULL,
  `edad` int(3) NOT NULL,
  `sexo` varchar(100) NOT NULL,
  `fumador` varchar(3) NOT NULL,
  `Trabaja` varchar(3) NOT NULL,
  `Descripcion` varchar(100) NOT NULL,
  UNIQUE KEY `nick` (`nickname`),
  KEY `nick_2` (`nickname`),
  KEY `nickname` (`nickname`),
  KEY `nickname_2` (`nickname`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

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

--
-- Estructura de tabla para la tabla `friends`
--

CREATE TABLE IF NOT EXISTS `friends` (
  `user1` char(135) DEFAULT NULL,
  `user2` char(135) DEFAULT NULL,
  KEY `user1` (`user1`),
  KEY `user2` (`user2`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

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

--
-- Estructura de tabla para la tabla `mensajes`
--

CREATE TABLE IF NOT EXISTS `mensajes` (
  `nickname` char(135) DEFAULT NULL,
  `friend` char(135) DEFAULT NULL,
  `comment` text,
  KEY `user1` (`nickname`),
  KEY `friend` (`friend`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

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

--
-- Estructura de tabla para la tabla `peticiones`
--

CREATE TABLE IF NOT EXISTS `peticiones` (
  `user1` varchar(100) NOT NULL,
  `user2` varchar(100) NOT NULL,
  KEY `user1` (`user1`),
  KEY `user2` (`user2`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

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

--
-- Estructura de tabla para la tabla `pisos`
--

CREATE TABLE IF NOT EXISTS `pisos` (
  `idPiso` int(11) NOT NULL AUTO_INCREMENT,
  `nickname` varchar(12) CHARACTER SET latin1 NOT NULL,
  `direccion` varchar(35) CHARACTER SET latin1 NOT NULL,
  `ciudad` varchar(35) CHARACTER SET latin1 NOT NULL,
  `codigopostal` varchar(35) CHARACTER SET latin1 NOT NULL,
  `comentarios` text CHARACTER SET latin1 NOT NULL,
  `foto` varchar(100) CHARACTER SET latin1 NOT NULL,
  `preciomes` int(10) NOT NULL,
  PRIMARY KEY (`idPiso`),
  KEY `propietario` (`nickname`),
  KEY `nickname` (`nickname`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf16 COLLATE=utf16_spanish_ci AUTO_INCREMENT=2 ;

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

--
-- Estructura de tabla para la tabla `usuarios`
--

CREATE TABLE IF NOT EXISTS `usuarios` (
  `nickname` varchar(10) NOT NULL,
  `password` varchar(100) NOT NULL,
  `location_id` int(11) NOT NULL,
  `enMochila` varchar(3) NOT NULL,
  UNIQUE KEY `nickname` (`nickname`),
  KEY `nickname_2` (`nickname`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Restricciones para tablas volcadas
--

--
-- Filtros para la tabla `datos_mochila`
--
ALTER TABLE `datos_mochila`
  ADD CONSTRAINT `datos_mochila_ibfk_1` FOREIGN KEY (`nickname`) REFERENCES `usuarios` (`nickname`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Filtros para la tabla `friends`
--
ALTER TABLE `friends`
  ADD CONSTRAINT `friends_ibfk_1` FOREIGN KEY (`user1`) REFERENCES `usuarios` (`nickname`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `friends_ibfk_2` FOREIGN KEY (`user2`) REFERENCES `usuarios` (`nickname`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Filtros para la tabla `mensajes`
--
ALTER TABLE `mensajes`
  ADD CONSTRAINT `mensajes_ibfk_1` FOREIGN KEY (`nickname`) REFERENCES `usuarios` (`nickname`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Filtros para la tabla `peticiones`
--
ALTER TABLE `peticiones`
  ADD CONSTRAINT `peticiones_ibfk_1` FOREIGN KEY (`user1`) REFERENCES `usuarios` (`nickname`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `peticiones_ibfk_2` FOREIGN KEY (`user2`) REFERENCES `usuarios` (`nickname`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Filtros para la tabla `pisos`
--
ALTER TABLE `pisos`
  ADD CONSTRAINT `pisos_ibfk_1` FOREIGN KEY (`nickname`) REFERENCES `usuarios` (`nickname`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Filtros para la tabla `usuarios`
--
ALTER TABLE `usuarios`
  ADD CONSTRAINT `usuarios_ibfk_1` FOREIGN KEY (`nickname`) REFERENCES `usuarios` (`nickname`) ON DELETE CASCADE ON UPDATE CASCADE;

/*!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 */;
