Advertisement
Fabio_LaF

Esquema BD PGC Fabio

Aug 13th, 2021 (edited)
1,896
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --ENUMs
  2. --------------------
  3. CREATE TYPE order_subtype AS ENUM ('sales', 'purchase');
  4. CREATE TYPE product_subtype AS ENUM('good', 'service');
  5.  
  6. --ORDER and ORDER ITEM
  7. ---------------------
  8.  
  9. CREATE TABLE IF NOT EXISTS order_table (
  10.     id integer,
  11.     order_date DATE NOT NULL DEFAULT CURRENT_DATE,
  12.     entry_date DATE NOT NULL DEFAULT CURRENT_DATE,
  13.     subtype order_subtype NOT NULL,
  14.     PRIMARY KEY (id)
  15. );
  16.  
  17. CREATE TABLE IF NOT EXISTS product (
  18.     id integer,
  19.     subtype product_subtype NOT NULL,
  20.     name VARCHAR(255) NOT NULL DEFAULT '',
  21.     introduction_date DATE NOT NULL DEFAULT CURRENT_DATE,
  22.     sales_discontinuation_date DATE NOT NULL DEFAULT '9999-12-31',
  23.     support_discontinuation_date DATE NOT NULL DEFAULT '9999-12-31',
  24.     comment VARCHAR(255) NOT NULL DEFAULT '',
  25.     PRIMARY KEY (id)
  26. );
  27.  
  28. CREATE TABLE IF NOT EXISTS order_item (
  29.     order_item_seq_id integer NOT NULL DEFAULT 1,
  30.     quantity smallint NOT NULL DEFAULT 0,
  31.     unit_price DECIMAL(13,4) NOT NULL DEFAULT 0,
  32.     estimated_delivery_date DATE NOT NULL DEFAULT '1000-01-01',
  33.     shipping_instructions VARCHAR(255) NOT NULL DEFAULT '',
  34.     comment VARCHAR(255) NOT NULL DEFAULT '',
  35.     order_id integer NOT NULL,
  36.     Product_id integer NOT NULL,
  37.     PRIMARY KEY (order_item_seq_id, order_id),
  38.     FOREIGN KEY (order_id) REFERENCES order_table(id),
  39.     FOREIGN KEY (Product_id) REFERENCES product(id)
  40. );
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement