-
Notifications
You must be signed in to change notification settings - Fork 0
/
order_product.sql
35 lines (31 loc) · 947 Bytes
/
order_product.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
CREATE TABLE order_product (
id number(9) NOT NULL PRIMARY KEY,
order_id number(9) NOT NULL,
product_id number(9) NOT NULL,
price number NOT NULL,
quantity number(3) NOT NULL,
created_at date,
created_by varchar2(50),
updated_at date default sysdate,
updated_by varchar2(50) default user,
CONSTRAINT order_pr_pr_fk FOREIGN KEY (product_id) REFERENCES products(id),
CONSTRAINT order_pr_order_fk FOREIGN KEY (order_id) REFERENCES orders(id)
);
CREATE SEQUENCE order_product_seq START WITH 1 INCREMENT BY 1;
CREATE OR REPLACE TRIGGER order_product_bef_ins
BEFORE INSERT
ON order_product FOR EACH ROW
BEGIN
:new.id := order_product_seq.nextval;
:new.created_at := sysdate;
:new.created_by := user;
:new.updated_at := sysdate;
:new.updated_by := user;
END;
CREATE OR REPLACE TRIGGER order_product_bef_upd
BEFORE UPDATE
ON order_product FOR EACH ROW
BEGIN
:new.updated_at := sysdate;
:new.updated_by := user;
END;