1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
--
-- Structure de la table `preferences`
--
CREATE TABLE `preferences` (
`id` tinyint(3) unsigned NOT NULL auto_increment COMMENT 'l''identifiant préference',
`preference` varchar(50) NOT NULL COMMENT 'le nom de la preference',
PRIMARY KEY (`id`),
UNIQUE KEY `preference` (`preference`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='table des preferences' AUTO_INCREMENT=5 ;
--
-- Contenu de la table `preferences`
--
INSERT INTO `preferences` (`id`, `preference`) VALUES
(1, 'preference 1'),
(2, 'preference 2'),
(3, 'preference 3'),
(4, 'preference 4');
-- --------------------------------------------------------
--
-- Structure de la table `products`
--
CREATE TABLE `products` (
`id` smallint(5) unsigned NOT NULL auto_increment COMMENT 'li''dentifiant catalogue',
`product` varchar(50) NOT NULL COMMENT 'le produit',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='table des produits' AUTO_INCREMENT=5 ;
--
-- Contenu de la table `products`
--
INSERT INTO `products` (`id`, `product`) VALUES
(1, 'produit 1'),
(2, 'produit 2'),
(3, 'produit 3'),
(4, 'produit 4');
-- --------------------------------------------------------
--
-- Structure de la table `products_preferences`
--
CREATE TABLE `products_preferences` (
`product_id` smallint(5) unsigned NOT NULL COMMENT 'l''identifiant produit',
`preference_id` tinyint(3) unsigned NOT NULL COMMENT 'l''identifiant preference',
UNIQUE KEY `catalog_id` (`product_id`,`preference_id`),
KEY `preference_id` (`preference_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='table d''association des préférences produits';
--
-- RELATIONS POUR LA TABLE `products_preferences`:
-- `preference_id`
-- `preferences` -> `id`
-- `product_id`
-- `products` -> `id`
--
--
-- Contenu de la table `products_preferences`
--
INSERT INTO `products_preferences` (`product_id`, `preference_id`) VALUES
(2, 1),
(3, 2),
(1, 3),
(1, 4);
-- --------------------------------------------------------
--
-- Structure de la table `users`
--
CREATE TABLE `users` (
`id` tinyint(3) unsigned NOT NULL auto_increment,
`username` varchar(20) NOT NULL COMMENT 'Le compte de l''utilisateur',
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='table des utilisateurs' AUTO_INCREMENT=3 ;
--
-- Contenu de la table `users`
--
INSERT INTO `users` (`id`, `username`) VALUES
(1, 'utilisateur 1'),
(2, 'utilisateur 2');
-- --------------------------------------------------------
--
-- Structure de la table `users_preferences`
--
CREATE TABLE `users_preferences` (
`user_id` tinyint(3) unsigned NOT NULL COMMENT 'l''identifiant de l''utilisateur',
`preference_id` tinyint(3) unsigned NOT NULL COMMENT 'l''identifiant de la préference',
UNIQUE KEY `user_id` (`user_id`,`preference_id`),
KEY `preference_id` (`preference_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='table d''association des préférences utilisateurs';
--
-- RELATIONS POUR LA TABLE `users_preferences`:
-- `preference_id`
-- `preferences` -> `id`
-- `user_id`
-- `users` -> `id`
--
--
-- Contenu de la table `users_preferences`
--
INSERT INTO `users_preferences` (`user_id`, `preference_id`) VALUES
(1, 2),
(1, 3),
(1, 4),
(2, 4);
--
-- Contraintes pour les tables exportées
--
--
-- Contraintes pour la table `products_preferences`
--
ALTER TABLE `products_preferences`
ADD CONSTRAINT `products_preferences_ibfk_3` FOREIGN KEY (`preference_id`) REFERENCES `preferences` (`id`) ON DELETE CASCADE,
ADD CONSTRAINT `products_preferences_ibfk_2` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE CASCADE;
--
-- Contraintes pour la table `users_preferences`
--
ALTER TABLE `users_preferences`
ADD CONSTRAINT `users_preferences_ibfk_2` FOREIGN KEY (`preference_id`) REFERENCES `preferences` (`id`) ON DELETE CASCADE,
ADD CONSTRAINT `users_preferences_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE; |
Partager