Bonjour,
Pour m'exercer, j'ai conçu une base de donnée très simple ayant 2 table :
Une table personne et une table voiture. La relation entre les 2 tables se nomme avoir et a une relation de 0,n de chaque coté.
Je précise que je travail sous mysql avec la méthode merise.
Pour générer mon script j'utilise POWERAMC
Voici le script généré :
Lors de mes formations j'utilisais la même syntaxe mis a part que je ne faisais aucun alter table et tout semblait fonctionner correctement.
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 drop table if exists AVOIR; drop table if exists PERSONNE; drop table if exists VOITURE; /*==============================================================*/ /* Table : AVOIR */ /*==============================================================*/ create table AVOIR ( ID_PERSONNE numeric(8,0) not null, ID_VOITURE numeric(8,0) not null, primary key (ID_PERSONNE, ID_VOITURE) ); /*==============================================================*/ /* Table : PERSONNE */ /*==============================================================*/ create table PERSONNE ( ID_PERSONNE numeric(8,0) not null, NOM text, PRENOM text, primary key (ID_PERSONNE) ); /*==============================================================*/ /* Table : VOITURE */ /*==============================================================*/ create table VOITURE ( ID_VOITURE numeric(8,0) not null, MODELE text, primary key (ID_VOITURE) ); alter table AVOIR add constraint FK_AVOIR foreign key (ID_VOITURE) references VOITURE (ID_VOITURE) on delete restrict on update restrict; alter table AVOIR add constraint FK_AVOIR2 foreign key (ID_PERSONNE) references PERSONNE (ID_PERSONNE) on delete restrict on update restrict;
Pourriez vous m'indiquer l'utilité des 2 alter table et si ils sont indispensable
Partager