-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathtessiland.ddl
More file actions
53 lines (42 loc) · 1.54 KB
/
tessiland.ddl
File metadata and controls
53 lines (42 loc) · 1.54 KB
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
-- Tables creation -------------------------------------------------------------
create database if not exists Tessiland;
use Tessiland;
create table if not exists TAG (
name varchar(32) not null,
constraint tag_pk primary key (name)
);
create table if not exists MATERIAL (
code int not null auto_increment,
description varchar(64) not null,
constraint material_pk primary key (code)
);
create table if not exists PRODUCT (
code int not null auto_increment,
name varchar(64) not null,
description varchar(5000),
constraint product_pk primary key (code)
);
create table if not exists COMPOSITION (
product_code int not null,
material_code int not null,
percent float(1) not null,
constraint composition_pk primary key (product_code, material_code)
);
create table if not exists TAGGED (
product_code int not null,
tag_name varchar(32) not null,
constraint tagged_pk primary key (tag_name, product_code)
);
-- Constraints -----------------------------------------------------------------
alter table COMPOSITION add constraint composition_references_material
foreign key (material_code)
references MATERIAL (code);
alter table COMPOSITION add constraint composition_references_product
foreign key (product_code)
references PRODUCT (code);
alter table TAGGED add constraint tagged_references_tag
foreign key (tag_name)
references TAG (name);
alter table TAGGED add constraint tagged_references_product
foreign key (product_code)
references PRODUCT (code);