aboutsummaryrefslogtreecommitdiff
path: root/opdracht-1/q2.sql
blob: fda5f53b1c4d47465fd7b561672d00c384373c28 (plain)
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
create table if not exists Klant (
  ID int unsigned not null auto_increment,
  Naam varchar(45) null,
  Postcode varchar(45) not null,
  Huisnummer int not null,
  Telefoonnummer int null,
  primary key (ID)
);

create table if not exists `Order` (
  ID int unsigned not null auto_increment,
  KlantID int unsigned not null,
  Besteldatum date not null,
  Status varchar(45) not null,
  primary key (ID),
  foreign key (KlantID) references Klant(ID)
);

create table if not exists Product (
  ID int unsigned not null auto_increment,
  Naam varchar(45) not null unique,
  Eenheid varchar(45) not null,
  Prijs FLOAT(24) not null,
  Beschrijving varchar(500) not null,
  primary key (ID)
);

create table if not exists OrderProduct (
  ID int unsigned not null auto_increment,
  OrderID int unsigned not null,
  ProductID int unsigned not null,
  Aantal int unsigned not null,
  primary key (ID),
  foreign key (OrderID) references `Order`(ID),
  foreign key (ProductID) references Product(ID),
  unique(OrderID, ProductID)
);