设计一个结构化数据库来聊天,一个表或多个表



下午好,

  • 我正在考虑如何最好保持帖子sqlite表1或超过1,

  • 以一个聊天为例,如果可以的话,把它放在同一个表中更好,还是放在不同的表中更好?

(例1表)

http://cmanios.wordpress.com/2013/10/29/read-sms-directly-from-sqlite-database-in-android/

  • 我认为如果我们把所有的信息放在一个表中会更容易信息溢出(堆栈溢出)

android sqlite表的限制:(相关主题)

Android应用程序中SQLite数据库的最大大小

Android中的SQLite数据库限制

  • 我的意思是我可以在一个表中包含更多的消息。从我的角度来看,作为一个程序员,我想创建多个表。

  • 示例1和x表:

    • (1表) (Where user = "select ")只需要查看特定用户,例如"用户1和用户2的消息"

表:(user1 + user2 + user3…userx)

+-----------------------------------------------------------------------------------------------------------------+
| date                | date_sent             | person    |  body                         |
|------------------------------------------------------------------------------------------------------------------
| 2013-10-20 13:48:18 | 2013-10-20 13:48:16   |   User1   | Hello Christos! How are you?              |
| 2013-10-20 16:34:03 | 1970-01-01 02:00:00   |   User2   | Fine, thanks ! I configure the left MFD of a F-16 jet |
| 2013-10-20 16:40:02 | 2013-10-20 16:40:01   |   User3   | Awesome! I am throwing a party tomorrow at 21:45!     |
| 2013-10-20 17:15:15 | 1970-01-01 02:00:00   |   Userx   | Thanks! I will be there!                  |
+-----------------------------------------------------------------------------------------------------------------+

- (2个或更多的表) easy select all table

+-----------------------------------------------------------------------------------------------------------------+
| date                | date_sent             | person    |  body                         |
|------------------------------------------------------------------------------------------------------------------
| 2013-10-20 13:48:18 | 2013-10-20 13:48:16   |   User1   | Hello Christos! How are you?              |
| 2013-10-20 16:34:03 | 1970-01-01 02:00:00   |   User2   | Fine, thanks ! I configure the left MFD of a F-16 jet |
| 2013-10-20 16:40:02 | 2013-10-20 16:40:01   |   User1   | Awesome! I am throwing a party tomorrow at 21:45!     |
| 2013-10-20 17:15:15 | 1970-01-01 02:00:00   |   User2   | Thanks! I will be there!                  |
+-----------------------------------------------------------------------------------------------------------------+
+-----------------------------------------------------------------------------------------------------------------+
| date                | date_sent             | person    |  body                         |
|------------------------------------------------------------------------------------------------------------------
| 2013-10-20 13:48:18 | 2013-10-20 13:48:16   |   User1   | Hello Christos! How are you?              |
| 2013-10-20 16:34:03 | 1970-01-01 02:00:00   |   User3   | Fine, thanks ! I configure the left MFD of a F-16 jet |
| 2013-10-20 16:40:02 | 2013-10-20 16:40:01   |   User1   | Awesome! I am throwing a party tomorrow at 21:45!     |
| 2013-10-20 17:15:15 | 1970-01-01 02:00:00   |   User3   | Thanks! I will be there!                  |
+-----------------------------------------------------------------------------------------------------------------+

。...

  • 我认为适当,创建多个表,我们就不会有存储问题,全部在一个表中。

  • 谁能告诉我哪个是最好的方法?或者如果我是错误的概念

您在sqlite中提供的大小限制链接都表明这应该不是一个真正的问题。

如果你真的认为你会到达:

http://www.sqlite.org/limits.html

一个表的理论最大行数是264(18446744073709551616或约1.8e+19)。此限制无法达到因为最大数据库大小将达到140 tb第一。一个140tb的数据库最多只能容纳大约1e+13行,然后只有当没有下标并且每一行包含很少的数据

在android设备上…我想也许你需要重新考虑一下这个话题。

下一个问题:

你应该在运行中创建/删除表吗?这是一个非常糟糕的主意——它很容易引起奇怪的问题。我不是说你不能这样做,但这不是做这种事情的正常方式。

个人-一个数据库。如果你真的觉得你需要分手,一个粗略的方法可能是这样的:

MyDatabase:
  tables:               fields
      user         UserUuid,name,
      message      UserUuid,MessageId,MessageText,to, from, timestamp
      attachments  MessageId,AttacmentId,AttachmentContent

这将允许您创建新用户并将其链接到消息和附件,同时保持比所有内容都在一个表中更好的组织,并将避免您在运行中创建/销毁表。你可能会找到一个更适合你具体需求的组织结构图,但这应该会让你开始工作。

相关内容

最新更新