Bonjour à tous,
je crée une BD en utilisant http://ondras.zarovi.cz/sql/demo/ (pour éviter de coder directement en dur et gagner du temps)
voici sa representation (cf code en bas aussi )
je voudrais que table1, table...4 soient liée à la table product, j'ai donc crée des clés étrangère pour chaque table reliée a product. Cependant, je ne sais pas comment remplir leurs champ. Ca doit pas être compliqué mais sur les forum on explique juste ce que c'est et pas comment on rempli son champ ^^
En exemple image la clé etrangere de la table4, que remplir la dedans en gros:
Est ce que je dois utiliser la clé primaire 'id' de product ? ou juste les mettre en auto-increment ? (j'ai laissé le champ rempli par défaut pour le moment, comme sur l'image du dessus)
N’hésitez pas a me faire des remarques ou a me demender plus de précisions.
d'avance merci.
code sql actuel ci dessous:
ou en xml:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 -- --- -- Globals -- --- -- SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; -- SET FOREIGN_KEY_CHECKS=0; -- --- -- Table 'product' -- -- --- DROP TABLE IF EXISTS `product`; CREATE TABLE `product` ( `id` INTEGER NOT NULL AUTO_INCREMENT, `id_table1` INTEGER NULL DEFAULT NULL, `id_table2` INTEGER NULL DEFAULT NULL, `id_table3` INTEGER NULL DEFAULT NULL, `id_table4` INTEGER NULL DEFAULT NULL, PRIMARY KEY (`id`) ); -- --- -- Table 'table1' -- -- --- DROP TABLE IF EXISTS `table1`; CREATE TABLE `table1` ( `id` INTEGER NULL AUTO_INCREMENT DEFAULT NULL, `ch_t1` INTEGER NULL DEFAULT NULL, PRIMARY KEY (`id`) ); -- --- -- Table 'table2' -- -- --- DROP TABLE IF EXISTS `table2`; CREATE TABLE `table2` ( `id` INTEGER NULL AUTO_INCREMENT DEFAULT NULL, `ch_t2` INTEGER NULL DEFAULT NULL, PRIMARY KEY (`id`) ); -- --- -- Table 'table3' -- -- --- DROP TABLE IF EXISTS `table3`; CREATE TABLE `table3` ( `id` INTEGER NULL AUTO_INCREMENT DEFAULT NULL, `ch_t3` INTEGER NULL DEFAULT NULL, PRIMARY KEY (`id`) ); -- --- -- Table 'table4' -- -- --- DROP TABLE IF EXISTS `table4`; CREATE TABLE `table4` ( `id` INTEGER NULL AUTO_INCREMENT DEFAULT NULL, `ch_t4` INTEGER NULL DEFAULT NULL, PRIMARY KEY (`id`) ); -- --- -- Foreign Keys -- --- ALTER TABLE `product` ADD FOREIGN KEY (id_table1) REFERENCES `table1` (`id`); ALTER TABLE `product` ADD FOREIGN KEY (id_table2) REFERENCES `table2` (`id`); ALTER TABLE `product` ADD FOREIGN KEY (id_table3) REFERENCES `table3` (`id`); ALTER TABLE `product` ADD FOREIGN KEY (id_table4) REFERENCES `table4` (`id`); -- --- -- Table Properties -- --- -- ALTER TABLE `product` ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; -- ALTER TABLE `table1` ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; -- ALTER TABLE `table2` ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; -- ALTER TABLE `table3` ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; -- ALTER TABLE `table4` ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; -- --- -- Test Data -- --- -- INSERT INTO `product` (`id`,`id_table1`,`id_table2`,`id_table3`,`id_table4`) VALUES -- ('','','','',''); -- INSERT INTO `table1` (`id`,`ch_t1`) VALUES -- ('',''); -- INSERT INTO `table2` (`id`,`ch_t2`) VALUES -- ('',''); -- INSERT INTO `table3` (`id`,`ch_t3`) VALUES -- ('',''); -- INSERT INTO `table4` (`id`,`ch_t4`) VALUES -- ('','');
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 <?xml version="1.0" encoding="utf-8" ?> <!-- SQL XML created by WWW SQL Designer, https://github.com/ondras/wwwsqldesigner/ --> <!-- Active URL: http://ondras.zarovi.cz/sql/demo/ --> <sql> <datatypes db="mysql"> <group label="Numeric" color="rgb(238,238,170)"> <type label="Integer" length="0" sql="INTEGER" quote=""/> <type label="TINYINT" length="0" sql="TINYINT" quote=""/> <type label="SMALLINT" length="0" sql="SMALLINT" quote=""/> <type label="MEDIUMINT" length="0" sql="MEDIUMINT" quote=""/> <type label="INT" length="0" sql="INT" quote=""/> <type label="BIGINT" length="0" sql="BIGINT" quote=""/> <type label="Decimal" length="1" sql="DECIMAL" re="DEC" quote=""/> <type label="Single precision" length="0" sql="FLOAT" quote=""/> <type label="Double precision" length="0" sql="DOUBLE" re="DOUBLE" quote=""/> </group> <group label="Character" color="rgb(255,200,200)"> <type label="Char" length="1" sql="CHAR" quote="'"/> <type label="Varchar" length="1" sql="VARCHAR" quote="'"/> <type label="Text" length="0" sql="MEDIUMTEXT" re="TEXT" quote="'"/> <type label="Binary" length="1" sql="BINARY" quote="'"/> <type label="Varbinary" length="1" sql="VARBINARY" quote="'"/> <type label="BLOB" length="0" sql="BLOB" re="BLOB" quote="'"/> </group> <group label="Date & Time" color="rgb(200,255,200)"> <type label="Date" length="0" sql="DATE" quote="'"/> <type label="Time" length="0" sql="TIME" quote="'"/> <type label="Datetime" length="0" sql="DATETIME" quote="'"/> <type label="Year" length="0" sql="YEAR" quote=""/> <type label="Timestamp" length="0" sql="TIMESTAMP" quote="'"/> </group> <group label="Miscellaneous" color="rgb(200,200,255)"> <type label="ENUM" length="1" sql="ENUM" quote=""/> <type label="SET" length="1" sql="SET" quote=""/> <type label="Bit" length="0" sql="bit" quote=""/> </group> </datatypes><table x="455" y="115" name="product"> <row name="id" null="0" autoincrement="1"> <datatype>INTEGER</datatype> </row> <row name="id_table1" null="1" autoincrement="0"> <datatype>INTEGER</datatype> <default>NULL</default><relation table="table1" row="id" /> </row> <row name="id_table2" null="1" autoincrement="0"> <datatype>INTEGER</datatype> <default>NULL</default><relation table="table2" row="id" /> </row> <row name="id_table3" null="1" autoincrement="0"> <datatype>INTEGER</datatype> <default>NULL</default><relation table="table3" row="id" /> </row> <row name="id_table4" null="1" autoincrement="0"> <datatype>INTEGER</datatype> <default>NULL</default><relation table="table4" row="id" /> </row> <key type="PRIMARY" name=""> <part>id</part> </key> </table> <table x="680" y="40" name="table1"> <row name="id" null="1" autoincrement="1"> <datatype>INTEGER</datatype> <default>NULL</default></row> <row name="ch_t1" null="1" autoincrement="0"> <datatype>INTEGER</datatype> <default>NULL</default></row> <key type="PRIMARY" name=""> <part>id</part> </key> </table> <table x="679" y="133" name="table2"> <row name="id" null="1" autoincrement="1"> <datatype>INTEGER</datatype> <default>NULL</default></row> <row name="ch_t2" null="1" autoincrement="0"> <datatype>INTEGER</datatype> <default>NULL</default></row> <key type="PRIMARY" name=""> <part>id</part> </key> </table> <table x="679" y="233" name="table3"> <row name="id" null="1" autoincrement="1"> <datatype>INTEGER</datatype> <default>NULL</default></row> <row name="ch_t3" null="1" autoincrement="0"> <datatype>INTEGER</datatype> <default>NULL</default></row> <key type="PRIMARY" name=""> <part>id</part> </key> </table> <table x="681" y="330" name="table4"> <row name="id" null="1" autoincrement="1"> <datatype>INTEGER</datatype> <default>NULL</default></row> <row name="ch_t4" null="1" autoincrement="0"> <datatype>INTEGER</datatype> <default>NULL</default></row> <key type="PRIMARY" name=""> <part>id</part> </key> </table> </sql>
Partager