DROP TABLE order_item;
DROP TABLE corder;
DROP TABLE customer; 
DROP TABLE product;
CREATE TABLE customer(
id NUMBER CONSTRAINT pk_customer PRIMARY KEY,
name VARCHAR2(30),
address VARCHAR2(60), 
zipcode NUMBER(5) CHECK(zipcode BETWEEN 00001 AND 99999));  
CREATE TABLE corder(
id NUMBER CONSTRAINT pk_order PRIMARY KEY,
odate DATE DEFAULT SYSDATE,
id_customer CONSTRAINT fk_order REFERENCES customer(id)); 
CREATE TABLE product(
id NUMBER CONSTRAINT pk_product PRIMARY KEY,
label VARCHAR2(30), 
stock NUMBER(10), 
price NUMBER(6,2) CHECK (price > 0));   
CREATE TABLE order_item(
id NUMBER CONSTRAINT pk_item PRIMARY KEY,
id_order CONSTRAINT fk1_item REFERENCES corder(id),
num_item NUMBER CONSTRAINT no_item NOT NULL, 
id_product CONSTRAINT fk2_item REFERENCES product(id),
quantity NUMBER,
CONSTRAINT unique_item UNIQUE(id_order, num_item)); 