This repository was archived by the owner on Oct 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathh2-create.sql
131 lines (113 loc) · 5.56 KB
/
h2-create.sql
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
create table o_address (
id bigint not null,
line1 varchar(100),
line2 varchar(100),
city varchar(100),
country_code varchar(255),
version bigint not null,
when_created timestamp not null,
when_updated timestamp not null,
constraint pk_o_address primary key (id))
;
create table be_contact (
id bigint not null,
first_name varchar(50),
last_name varchar(50),
email varchar(200),
phone varchar(20),
customer_id bigint not null,
version bigint not null,
when_created timestamp not null,
when_updated timestamp not null,
constraint pk_be_contact primary key (id))
;
create table contact_note (
id bigint not null,
contact_id bigint not null,
title varchar(255),
note clob,
version bigint not null,
when_created timestamp not null,
when_updated timestamp not null,
constraint pk_contact_note primary key (id))
;
create table o_country (
code varchar(255) not null,
name varchar(255),
constraint pk_o_country primary key (code))
;
create table be_customer (
id bigint not null,
status varchar(1),
inactive boolean,
name varchar(100),
registered timestamp,
comments varchar(1000),
billing_address_id bigint,
shipping_address_id bigint,
version bigint not null,
when_created timestamp not null,
when_updated timestamp not null,
constraint ck_be_customer_status check (status in ('B','G','M')),
constraint pk_be_customer primary key (id))
;
create table o_order (
id bigint not null,
status integer,
order_date date,
ship_date date,
customer_id bigint not null,
shipping_address_id bigint,
version bigint not null,
when_created timestamp not null,
when_updated timestamp not null,
constraint ck_o_order_status check (status in (0,1,2,3)),
constraint pk_o_order primary key (id))
;
create table o_order_detail (
id bigint not null,
order_id bigint,
order_qty integer,
ship_qty integer,
unit_price double,
product_id bigint,
version bigint not null,
when_created timestamp not null,
when_updated timestamp not null,
constraint pk_o_order_detail primary key (id))
;
create table o_product (
id bigint not null,
sku varchar(20),
name varchar(255),
version bigint not null,
when_created timestamp not null,
when_updated timestamp not null,
constraint pk_o_product primary key (id))
;
create sequence o_address_seq;
create sequence be_contact_seq;
create sequence contact_note_seq;
create sequence o_country_seq;
create sequence be_customer_seq;
create sequence o_order_seq;
create sequence o_order_detail_seq;
create sequence o_product_seq;
alter table o_address add constraint fk_o_address_country_1 foreign key (country_code) references o_country (code) on delete restrict on update restrict;
create index ix_o_address_country_1 on o_address (country_code);
alter table be_contact add constraint fk_be_contact_customer_2 foreign key (customer_id) references be_customer (id) on delete restrict on update restrict;
create index ix_be_contact_customer_2 on be_contact (customer_id);
alter table contact_note add constraint fk_contact_note_contact_3 foreign key (contact_id) references be_contact (id) on delete restrict on update restrict;
create index ix_contact_note_contact_3 on contact_note (contact_id);
alter table be_customer add constraint fk_be_customer_billingAddress_4 foreign key (billing_address_id) references o_address (id) on delete restrict on update restrict;
create index ix_be_customer_billingAddress_4 on be_customer (billing_address_id);
alter table be_customer add constraint fk_be_customer_shippingAddress_5 foreign key (shipping_address_id) references o_address (id) on delete restrict on update restrict;
create index ix_be_customer_shippingAddress_5 on be_customer (shipping_address_id);
alter table o_order add constraint fk_o_order_customer_6 foreign key (customer_id) references be_customer (id) on delete restrict on update restrict;
create index ix_o_order_customer_6 on o_order (customer_id);
alter table o_order add constraint fk_o_order_shippingAddress_7 foreign key (shipping_address_id) references o_address (id) on delete restrict on update restrict;
create index ix_o_order_shippingAddress_7 on o_order (shipping_address_id);
alter table o_order_detail add constraint fk_o_order_detail_order_8 foreign key (order_id) references o_order (id) on delete restrict on update restrict;
create index ix_o_order_detail_order_8 on o_order_detail (order_id);
alter table o_order_detail add constraint fk_o_order_detail_product_9 foreign key (product_id) references o_product (id) on delete restrict on update restrict;
create index ix_o_order_detail_product_9 on o_order_detail (product_id);