0
我怎样才能组织更多的表格/表格来存储Order History
?如何组织在DB中存储历史记录的表?
现在我的数据库结构非常简单,看看下面的代码:
CREATE TABLE category_table (
id SERIAL PRIMARY KEY NOT NULL,
name CHARACTER(250) NOT NULL
);
CREATE TABLE order_table (
id SERIAL PRIMARY KEY NOT NULL,
total_price DECIMAL(12, 2),
date TIMESTAMP WITH TIME ZONE DEFAULT now(),
product_amount INT
);
CREATE TABLE product_table (
id SERIAL PRIMARY KEY NOT NULL,
name CHARACTER VARYING(250) NOT NULL,
price DECIMAL(12, 2),
category_id INT,
CONSTRAINT category_fk FOREIGN KEY (category_id) REFERENCES category_table (id)
);
CREATE TABLE product_order_table (
product_id INT,
order_id INT,
CONSTRAINT product_fk FOREIGN KEY (product_id) REFERENCES product_table (id),
CONSTRAINT order_fk FOREIGN KEY (order_id) REFERENCES order_table (id)
);
我需要整理表/表为Order History
关于这两个限制:
-
1.我们可以删除记录形式表`order_table`
-
2.我们可以改变`order_table`
记录我在DB的设计需要咨询。
其实我不熟悉'触发函数'。 – Alex 2014-09-25 18:28:24
您可以阅读以下链接的一些示例:http://www.postgresql.org/docs/9.3/static/sql-createtrigger.html或http://www.postgresqltutor.com/create-trigger.html – PlsqlDev 2014-09-25 18:38:11
哦,感谢您的链接。 – Alex 2014-09-25 18:46:22