-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScript BD Interne.sql
More file actions
180 lines (161 loc) · 5.2 KB
/
Script BD Interne.sql
File metadata and controls
180 lines (161 loc) · 5.2 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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
CREATE TABLE public."Category"
(
category_id SERIAL,
category_name character varying(100) NOT NULL,
CONSTRAINT "Category_pkey" PRIMARY KEY (category_id)
)
WITH (
OIDS=FALSE
);
ALTER TABLE public."Category"
OWNER TO postgres;
CREATE TABLE public."Type"
(
type_id SERIAL,
type_name character varying(100) NOT NULL,
category_id integer NOT NULL,
CONSTRAINT "Type_pkey" PRIMARY KEY (type_id),
CONSTRAINT fk_category FOREIGN KEY (category_id)
REFERENCES public."Category" (category_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (
OIDS=FALSE
);
ALTER TABLE public."Type"
OWNER TO postgres;
CREATE TABLE public."TypeCaracteristic"
(
type_caracteristic_id SERIAL,
type_id integer NOT NULL,
type_caracteristic_name character varying(100) NOT NULL,
CONSTRAINT "TypeCaracteristic_pkey" PRIMARY KEY (type_caracteristic_id),
CONSTRAINT fk_type_id FOREIGN KEY (type_id)
REFERENCES public."Type" (type_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (
OIDS=FALSE
);
ALTER TABLE public."TypeCaracteristic"
OWNER TO postgres;
CREATE TABLE public."ProductCaracteristic"
(
type_caracteristic_id integer NOT NULL,
product_barcode character varying(100) NOT NULL,
product_caracteristic_value character varying(100) NOT NULL,
CONSTRAINT "ProductCaracteristic_pkey" PRIMARY KEY (type_caracteristic_id, product_barcode),
CONSTRAINT fk_type_caracteristic_id FOREIGN KEY (type_caracteristic_id)
REFERENCES public."TypeCaracteristic" (type_caracteristic_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT fk_product_barcode FOREIGN KEY (product_barcode)
REFERENCES public."Product" (product_barcode) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (
OIDS=FALSE
);
ALTER TABLE public."ProductCaracteristic"
OWNER TO postgres;
CREATE TABLE public."Product"
(
product_barcode character varying(100) NOT NULL,
product_name character varying(100) NOT NULL,
product_type integer NOT NULL,
product_trade_mark character varying(100) NOT NULL,
CONSTRAINT pk_product_barcode PRIMARY KEY (product_barcode),
CONSTRAINT fk_product_type FOREIGN KEY (product_type)
REFERENCES public."Type" (type_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (
OIDS=FALSE
);
ALTER TABLE public."Product"
OWNER TO postgres;
CREATE TABLE public."Wilaya"
(
wilaya_id integer NOT NULL,
wilaya_name character varying(50) NOT NULL,
CONSTRAINT "Wilaya_pkey" PRIMARY KEY (wilaya_id)
)
WITH (
OIDS=FALSE
);
ALTER TABLE public."Wilaya"
OWNER TO postgres;
CREATE TABLE public."City"
(
city_id integer NOT NULL,
city_name character varying(50) NOT NULL,
wilaya_id integer NOT NULL,
CONSTRAINT "City_pkey" PRIMARY KEY (city_id),
CONSTRAINT fk_city_wilaya_id FOREIGN KEY (wilaya_id)
REFERENCES public."Wilaya" (wilaya_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (
OIDS=FALSE
);
ALTER TABLE public."City"
OWNER TO postgres;
CREATE TABLE public."SalesPoint"
(
sales_point_id character varying(250) NOT NULL,
sales_point_name character varying(250) NOT NULL,
sales_point_lat real NOT NULL,
sales_point_lng real NOT NULL,
sales_point_address character varying(250) NOT NULL,
city_id integer NOT NULL,
sales_point_phone_number character varying(30) NOT NULL,
sales_point_website character varying(250) NOT NULL,
sales_point_rating real NOT NULL,
sales_point_picture OID NOT NULL,
CONSTRAINT "SalesPoint_pkey" PRIMARY KEY (sales_point_id),
CONSTRAINT fk_sales_point_city_id FOREIGN KEY (city_id)
REFERENCES public."City" (city_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (
OIDS=FALSE
);
ALTER TABLE public."SalesPoint"
OWNER TO postgres;
CREATE TABLE public."ProductSalesPoint"
(
sales_point_id character varying(250) NOT NULL,
product_barcode character varying(100) NOT NULL,
product_quantity integer NOT NULL,
product_price real NOT NULL,
CONSTRAINT pk_product_sales_point_id PRIMARY KEY (sales_point_id, product_barcode),
CONSTRAINT fk_product_barcode FOREIGN KEY (product_barcode)
REFERENCES public."Product" (product_barcode) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT fk_sales_point_id FOREIGN KEY (sales_point_id)
REFERENCES public."SalesPoint" (sales_point_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT valid_price CHECK (product_price >= 0::double precision),
CONSTRAINT valid_quantity CHECK (product_quantity >= 0)
)
WITH (
OIDS=FALSE
);
ALTER TABLE public."ProductSalesPoint"
OWNER TO postgres;
CREATE TABLE public."Notifications"
(
sales_point_id character varying(250) NOT NULL,
product_barcode character varying(100) NOT NULL,
notification_date_time timestamp NOT NULL,
notification_new_quantity integer NOT NULL,
notification_new_price real NOT NULL,
CONSTRAINT "Notifications_pkey" PRIMARY KEY (sales_point_id, product_barcode),
CONSTRAINT fk_sales_point_id_product_barcode FOREIGN KEY (sales_point_id, product_barcode)
REFERENCES public."ProductSalesPoint" (sales_point_id, product_barcode) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (
OIDS=FALSE
);
ALTER TABLE public."Notifications"
OWNER TO postgres;