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
|
CREATE TABLE t_category (id int primary key, nom text);
CREATE TABLE t_user (id int primary key, nom text);
CREATE TABLE t_picture (id int primary key, nom text);
CREATE TABLE t_product
(
id_product bigserial NOT NULL,
code character varying(5),
"name" character varying(50) NOT NULL,
description character varying(250) NOT NULL,
price_ht double precision NOT NULL,
stock_web integer NOT NULL,
picture_id integer,
category_id integer NOT NULL,
CONSTRAINT id_product PRIMARY KEY (id_product),
CONSTRAINT category_idep FOREIGN KEY (category_id)
REFERENCES t_category (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT picture_idp FOREIGN KEY (picture_id)
REFERENCES t_picture (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
);
CREATE TABLE t_order
(
id serial NOT NULL,
create_date date NOT NULL,
price_ht double precision NOT NULL,
user_id integer NOT NULL,
CONSTRAINT order_id PRIMARY KEY (id),
CONSTRAINT user_ido FOREIGN KEY (user_id)
REFERENCES t_user (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
);
CREATE TABLE t_order_product
(
id serial NOT NULL,
product_id integer NOT NULL,
quantity integer,
price_ht double precision NOT NULL,
order_id integer NOT NULL,
CONSTRAINT order_product_id PRIMARY KEY (id),
CONSTRAINT order_idop FOREIGN KEY (order_id)
REFERENCES t_order (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT product_idop FOREIGN KEY (product_id)
REFERENCES t_product (id_product) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
);
INSERT INTO t_category (id, nom)
VALUES (1,'plante'), (2,'accessoire'), (3,'gâteau'), (4,'livre');
INSERT INTO t_picture (id, nom)
VALUES (1,'picture1'), (2,'picture2'), (3,'picture3'), (4,'picture4'),(5,'picture5'), (6,'picture6');
INSERT INTO t_user (id, nom)
VALUES (1,'Jim'), (2,'Jhon'), (3,'Silvie');
INSERT INTO t_order (id, user_id, create_date, price_ht)
VALUES (1,1,'1999-12-23',12.5), (2,2,'2009-08-03',60.6);
INSERT INTO t_product VALUES
(1,'B78','Boite','blabla',4.5,4,4,2),
(2,'Bo87','Livre Tao','blabla2',12.2,17,3,4),
(3,'T034','Oolong','blabla3',9.5,1000,2,1),
(4,'G678','Bonbon','blabla4',5,10,5,3);
INSERT INTO t_order_product VALUES (1,3,100,9.5,1); |
Partager