Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentes Révision précédente | |||
| info:mysql:concatenation_plusieurs_bases_mysql [2023/03/20 14:21] – supprimée - modification externe (Unknown date) 127.0.0.1 | info:mysql:concatenation_plusieurs_bases_mysql [2023/03/20 14:21] (Version actuelle) – ↷ Page déplacée de info:concatenation_plusieurs_bases_mysql à info:mysql:concatenation_plusieurs_bases_mysql radeff | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| + | |||
| + | ====== concaténation plusieurs bases MySQL ====== | ||
| + | |||
| + | ===== précautions à prendre et solutions, ou pourquoi mysql est parfois benêt! ===== | ||
| + | |||
| + | lorsqu' | ||
| + | |||
| + | exemple | ||
| + | <code mysql> | ||
| + | -- lancer mysql | ||
| + | mysql | ||
| + | -- creer base testA | ||
| + | create database testA; | ||
| + | use testA; | ||
| + | -- creer table A.a | ||
| + | CREATE TABLE `a` ( | ||
| + | `a` text NOT NULL, | ||
| + | `b` text NOT NULL, | ||
| + | `c` text NOT NULL | ||
| + | ) ENGINE=MyISAM DEFAULT CHARSET=latin1; | ||
| + | |||
| + | -- | ||
| + | -- Contenu de la table `a` | ||
| + | -- | ||
| + | |||
| + | INSERT INTO `a` (`a`, `b`, `c`) VALUES | ||
| + | (' | ||
| + | (' | ||
| + | (' | ||
| + | |||
| + | |||
| + | -- creer base testB | ||
| + | create database testB; | ||
| + | use testB; | ||
| + | -- creer table B.a | ||
| + | -- noter structure identique mais ordre different | ||
| + | -- | ||
| + | -- Structure de la table `a` | ||
| + | -- | ||
| + | |||
| + | CREATE TABLE `a` ( | ||
| + | `b` text NOT NULL, | ||
| + | `c` text NOT NULL, | ||
| + | `a` text NOT NULL | ||
| + | ) ENGINE=MyISAM DEFAULT CHARSET=latin1; | ||
| + | |||
| + | -- | ||
| + | -- Contenu de la table `a` | ||
| + | -- | ||
| + | |||
| + | INSERT INTO `a` (`b`, `c`, `a`) VALUES | ||
| + | (' | ||
| + | |||
| + | |||
| + | -- Base de données: `testC` | ||
| + | -- creer base testC | ||
| + | create database testC; | ||
| + | use testC; | ||
| + | -- creer table C.a | ||
| + | -- noter structure identique mais ordre different | ||
| + | -- | ||
| + | -- Structure de la table `a` | ||
| + | -- | ||
| + | |||
| + | CREATE TABLE `a` ( | ||
| + | `c` text NOT NULL, | ||
| + | `b` text NOT NULL, | ||
| + | `a` text NOT NULL | ||
| + | ) ENGINE=MyISAM DEFAULT CHARSET=latin1; | ||
| + | |||
| + | -- | ||
| + | -- Contenu de la table `a` | ||
| + | -- | ||
| + | |||
| + | INSERT INTO `a` (`c`, `b`, `a`) VALUES | ||
| + | (' | ||
| + | |||
| + | ------------------------- | ||
| + | </ | ||
| + | |||
| + | ==== et maintenant le test ==== | ||
| + | |||
| + | |||
| + | < | ||
| + | INSERT INTO `testA`.`a` | ||
| + | SELECT * | ||
| + | FROM `testB`.`a` ; | ||
| + | |||
| + | INSERT INTO `testA`.`a` | ||
| + | SELECT * | ||
| + | FROM `testC`.`a` ; | ||
| + | </ | ||
| + | |||
| + | - Resultat de SELECT * FROM `testA`.`a`; | ||
| + | |||
| + | ^a ^b ^c ^ | ||
| + | |Aa |Bb |Cc | | ||
| + | |Cc |Cb |Ca | | ||
| + | |Bb |Bc |Ba | | ||
| + | |||
| + | |||
| + | |||
| + | On voit (notamment) que le champs c de TestC est devenu le champs a de TestA, et que le champs b de TestB est devenue le champs a de TestA | ||
| + | |||
| + | ====== avec le critère " | ||
| + | |||
| + | :!: --> prudence, écrire tous les noms des champs | ||
| + | |||
| + | le plus simple pour les récupérer, | ||
| + | |||
| + | ====== Script propre | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | < | ||
| + | INSERT INTO `testA`.`a` | ||
| + | SELECT `a`, `b`, `c` | ||
| + | FROM `testB`.`a` ; | ||
| + | |||
| + | INSERT INTO `testA`.`a` | ||
| + | SELECT `a`, `b`, `c` | ||
| + | FROM `testC`.`a` | ||
| + | </ | ||
| + | |||
| + | ==== et maintenant le test ==== | ||
| + | - Resultat de SELECT * FROM `testA`.`a`; | ||
| + | |||
| + | ^a ^b ^c ^ | ||
| + | |Aa |Bb |Cc | | ||
| + | |Ca |Cb |Cc | | ||
| + | |Ba |Bc |Bc | | ||
| + | |||
| + | :-D korrekt! | ||