Skip to content

Instantly share code, notes, and snippets.

@jasoet
Created October 6, 2012 02:13
Show Gist options
  • Save jasoet/3843468 to your computer and use it in GitHub Desktop.
Save jasoet/3843468 to your computer and use it in GitHub Desktop.
DDL
CREATE SEQUENCE category_category_id_seq_1;
CREATE TABLE category (
category_id INTEGER NOT NULL DEFAULT nextval('category_category_id_seq_1'),
name VARCHAR(55) NOT NULL,
CONSTRAINT category_id PRIMARY KEY (category_id)
);
ALTER SEQUENCE category_category_id_seq_1 OWNED BY category.category_id;
CREATE SEQUENCE product_product_id_seq;
CREATE TABLE product (
product_id INTEGER NOT NULL DEFAULT nextval('product_product_id_seq'),
name VARCHAR(155) NOT NULL,
description VARCHAR(255) NOT NULL,
price DOUBLE PRECISION NOT NULL,
expiredDate DATE NOT NULL,
category_id INTEGER NOT NULL,
CONSTRAINT product_id PRIMARY KEY (product_id)
);
ALTER SEQUENCE product_product_id_seq OWNED BY product.product_id;
ALTER TABLE product ADD CONSTRAINT category_product_fk
FOREIGN KEY (category_id)
REFERENCES category (category_id)
ON DELETE NO ACTION
ON UPDATE NO ACTION
NOT DEFERRABLE;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment