0

我正在尝试提出一个用于存储来自 SMS 应用程序的消息的模式。它需要存储从发件人发送的消息以及发送给该发件人的消息。如果有人能告诉我做到这一点的最佳方法,我们将不胜感激。如果这有什么不同,我正在使用 Postgresql。

4

2 回答 2

2

以下是您可以简要执行的操作:

表联系人:

CREATE TABLE contact
(
  contact_id bigserial NOT NULL,
  contact_name character varying,
  contact_phone_number character varying(40),
  CONSTRAINT contact_pkey PRIMARY KEY (contact_id)
)
WITH (
  OIDS=FALSE
);

还有短信表:

CREATE TABLE sms
(
  msg_id bigint NOT NULL DEFAULT nextval('message_msg_id_seq'::regclass),
  sender_id bigint,
  receiver_id bigint,
  msg_content text,
  CONSTRAINT message_pkey PRIMARY KEY (msg_id),
  CONSTRAINT sms_receiver_id_fkey FOREIGN KEY (receiver_id)
      REFERENCES contact (contact_id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT sms_sender_id_fkey FOREIGN KEY (sender_id)
      REFERENCES contact (contact_id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION
    )
WITH (
  OIDS=FALSE
);
于 2013-03-10T17:07:14.827 回答
1

你可以用两张桌子来做:

用户表:id, name, {other info about your user}

消息表:id, sender, receiver, message, {other info about message}

于 2013-03-10T16:50:21.140 回答