Skip to content

Instantly share code, notes, and snippets.

@mavimo
Created November 13, 2010 18:58
Show Gist options
  • Save mavimo/675548 to your computer and use it in GitHub Desktop.
Save mavimo/675548 to your computer and use it in GitHub Desktop.
file di creazione della struttura
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL';
CREATE SCHEMA IF NOT EXISTS `mydb` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
USE `mydb` ;
-- -----------------------------------------------------
-- Table `mydb`.`commento`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`commento` (
`id` INT NOT NULL ,
`autore` VARCHAR(45) NULL ,
PRIMARY KEY (`id`) )
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`libro`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`libro` (
`id` INT NOT NULL ,
`capitolo` VARCHAR(45) NULL ,
`paragrafo` VARCHAR(45) NULL ,
PRIMARY KEY (`id`) )
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`libro_has_commento`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`libro_has_commento` (
`commento_id` INT NOT NULL ,
`libro_id` INT NOT NULL ,
PRIMARY KEY (`commento_id`, `libro_id`) ,
INDEX `fk_commento_has_libro_libro1` (`libro_id` ASC) ,
CONSTRAINT `fk_commento_has_libro_commento`
FOREIGN KEY (`commento_id` )
REFERENCES `mydb`.`commento` (`id` )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_commento_has_libro_libro1`
FOREIGN KEY (`libro_id` )
REFERENCES `mydb`.`libro` (`id` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment