MySQL Forums
Forum List  »  French

Re: aide sur requete avec jointures
Posted by: seb seb
Date: August 17, 2010 06:28PM

Merci encore Jean,

Je ne savais pas qu'on pouvait faire d'un champ potentiellement NULL, une composante de clef primaire ! Je suis content de l'apprendre merci Jean !

Donc effectivement ce model convient a priori très bien. Il devrait résoudre mes problèmes de requête avec jointure qui donne mal à la tête ;o)
Il y aura probablement beaucoup de redondance pour le champ texte de chaque table maisje ne pense pas que ce soit tres grave...

Par contre, le probleme c'est qu'avec Mysql le type INT ne peut etre défini qu'en NOT NULL !!
et que par conséquent il semble impossible de faire une cles etrangère avec un ON DELETE SET NULL !

D'ailleurs, en exécutant le SQL de creation du model (cf plus bas), MySQL me retourne une (errno: 150)
"Error in foreign key constraint. You have defined a SET NULL condition though some of the columns are defined as NOT NULL."


Il existe un moyen de contourner le probleme ?

Merci encore pour ton aide


Commande SQL :

-- -----------------------------------------------------
-- Table `modules`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `modules` (
`idmodule` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`nommodule` VARCHAR(45) NULL ,
PRIMARY KEY (`idmodule`) )
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `chapitres`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `chapitres` (
`idchapitre` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`idmodule` BIGINT(20) UNSIGNED NULL DEFAULT NULL ,
`rankchapitre` INT UNSIGNED NULL DEFAULT NULL ,
`nomchapitre` TEXT NULL ,
PRIMARY KEY (`idchapitre`, `idmodule`, `rankchapitre`) ,
INDEX (`idmodule` ASC) ,
INDEX (`idchapitre` ASC) ,
INDEX (`rankchapitre` ASC)
)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `sequences`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `sequences` (
`idsequence` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`idchapitre` BIGINT(20) UNSIGNED NULL DEFAULT NULL ,
`ranksequence` INT UNSIGNED NULL DEFAULT NULL ,
`nomsequence` TEXT NULL ,
PRIMARY KEY (`idsequence`, `idchapitre`, `ranksequence`) ,
INDEX (`idchapitre` ASC) ,
INDEX (`idsequence` ASC) ,
INDEX (`ranksequence` ASC)
)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `briques`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `briques` (
`idbrique` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT ,
`idsequence` BIGINT(20) UNSIGNED NULL DEFAULT NULL ,
`rankbrique` INT UNSIGNED NULL DEFAULT NULL ,
`nombrique` TEXT NULL ,
PRIMARY KEY (`idbrique`, `rankbrique`, `idsequence`) ,
INDEX (`idsequence` ASC) ,
INDEX (`idbrique` ASC) ,
INDEX (`rankbrique` ASC)
)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- AJOUT DES CONTRAINTES DE CLES ETRANGERES
-- -----------------------------------------------------


ALTER TABLE chapitres ADD CONSTRAINT FOREIGN KEY (idmodule )
REFERENCES modules (idmodule )
ON DELETE SET NULL
ON UPDATE NO ACTION ;

ALTER TABLE sequences ADD CONSTRAINT FOREIGN KEY (idchapitre )
REFERENCES chapitres (idchapitre )
ON DELETE SET NULL
ON UPDATE NO ACTION ;

ALTER TABLE briques ADD CONSTRAINT FOREIGN KEY (idsequence )
REFERENCES sequences (idsequence )
ON DELETE SET NULL
ON UPDATE NO ACTION ;

Options: ReplyQuote


Subject
Views
Written By
Posted
5246
August 17, 2010 07:45AM
2863
August 17, 2010 09:25AM
2211
August 17, 2010 09:46AM
2372
August 17, 2010 10:21AM
2088
August 17, 2010 10:32AM
2191
August 17, 2010 11:31AM
2337
August 17, 2010 01:12PM
Re: aide sur requete avec jointures
3524
August 17, 2010 06:28PM
2381
August 17, 2010 10:39PM
2162
August 18, 2010 06:13AM
2263
August 18, 2010 06:59AM
2077
August 18, 2010 10:12AM
2196
August 18, 2010 10:40AM
3478
August 22, 2010 04:07AM
2057
August 31, 2010 03:28AM
2479
August 31, 2010 03:29AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.