Skip to content

Instantly share code, notes, and snippets.

@jrbistuer
Last active December 25, 2015 03:09
Show Gist options
  • Save jrbistuer/6907952 to your computer and use it in GitHub Desktop.
Save jrbistuer/6907952 to your computer and use it in GitHub Desktop.
Archivo script de MySQL para utilizar en el ejemplo de Hibernate 4
CREATE DATABASE IF NOT EXISTS `adritah_hibernate`;
USE `adritah_hibernate`;
DROP TABLE IF EXISTS `cliente`;
CREATE TABLE `cliente` (
`idCliente` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`nombre` varchar(45) NOT NULL,
`apellidos` varchar(45) NOT NULL,
PRIMARY KEY (`idCliente`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `direccion`;
CREATE TABLE `direccion` (
`idCliente` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`calle` varchar(45) NOT NULL,
`dp` varchar(45) NULL,
`poblacion` varchar(45) NOT NULL,
`provincia` varchar(45) NOT NULL,
PRIMARY KEY (`idCliente`),
CONSTRAINT `FK_IDCLIENTE` FOREIGN KEY (`idCliente`)
REFERENCES `cliente` (`idCliente`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `correoelectronico`;
CREATE TABLE `correoelectronico` (
`idCorreoelectronico` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`correoelectronico` varchar(45) NOT NULL,
`idCliente` int(11) UNSIGNED NOT NULL,
PRIMARY KEY (`idCorreoelectronico`),
KEY `FK_CORREOELECTRONICO_IDCLIENTE` (`idCliente`),
CONSTRAINT `FK_CORREOELECTRONICO_IDCLIENTE` FOREIGN KEY (`idCliente`)
REFERENCES `cliente` (`idCliente`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `producto`;
CREATE TABLE `producto` (
`idProducto` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`nombre` varchar(45) NOT NULL,
`cantidades` int(11) NOT NULL,
PRIMARY KEY (`idProducto`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `clienteproducto`;
CREATE TABLE `clienteproducto` (
`idCliente` int(11) UNSIGNED NOT NULL,
`idProducto` int(11) UNSIGNED NOT NULL,
PRIMARY KEY (`idCliente`,`idProducto`),
CONSTRAINT `FK_IDPRODUCTO_CP` FOREIGN KEY (`idProducto`) REFERENCES `producto` (`idProducto`),
CONSTRAINT `FK_IDCLIENTE_CP` FOREIGN KEY (`idCliente`) REFERENCES `cliente` (`idCliente`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment