【问题标题】:Designing a structured database to chat, One table or more than one table设计结构化数据库进行聊天,一张表或多张表
【发布时间】:2014-04-29 08:12:53
【问题描述】:

下午好,

  • 我正在考虑最好将帖子保留在 sqlite 表 1 或多于 1,

  • 举个例子,聊天,最好把它全部放在一张桌子上(如果可以的话)还是放在不同的桌子上更好?

(示例 1 表)

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

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

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

Maximum SQLite Database Size in Android Application

SQLite database limits in Android

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

  • 示例 1 和 x 表:

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

表:(用户 1 + 用户 2 + 用户 3 ... 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 个或更多表) 轻松选择所有表

+-----------------------------------------------------------------------------------------------------------------+
| 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!                  |
+-----------------------------------------------------------------------------------------------------------------+

。 . . .

  • 我认为合适,创建多个表,我们不会有存储问题,都在一个表中。

  • 谁能告诉我最好的方法是什么?或者如果我的概念有误

【问题讨论】:

    标签: android mysql sql sqlite database-design


    【解决方案1】:

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

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

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

    一个表的理论最大行数是264 (18446744073709551616 或约 1.8e+19)。这个限制是无法达到的 因为将达到 140 TB 的最大数据库大小 第一的。一个 140 TB 的数据库最多只能保存大约 1e+13 行,然后仅当没有索引且每行 包含非常少的数据。

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

    下一个问题:

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

    个人 - 一个数据库。如果你真的觉得你需要打破它,一个粗略的方法可能是:

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

    这将允许您创建新用户并将他们链接到消息和附件,同时保持比所有内容都在一个表中更好的组织,并且可以避免您在运行中创建/销毁表。您可能会找到更适合您的特定需求的组织结构图,但这应该会让您滚动。

    【讨论】:

    • Nathaniel 你太棒了,现在我在查询 sql 中遇到问题: String selectQuery="" +"SELECT tm."+UsersDatabase.COLUMN_MESSAGE_TEXT+" FROM "+UsersDatabase.TABLE_MESSAGES+" as tm WHERE tm. "+UsersDatabase.COLUMN_USER_UID+ " = '"+userUid+"' 和 tm."+UsersDatabase.COLUMN_FROM +" = '"+from+"' 和 tm."+UsersDatabase.COLUMN_TO+" = '"+to+"'"; “我得到错误”:(1)在“from”附近:语法错误
    • 请为此提出一个新问题 - 在评论中真的很难阅读。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-28
    • 2011-03-14
    相关资源
    最近更新 更多