donglv6747 2012-01-16 07:03
浏览 51
已采纳

插入唯一值而不自动递增

For the sake of simplicity in explaining this, imagine a room full of people talking to each other. Every statement made by one person to another would be a record in this table, and all of these records have a unique ID assigned through auto-increment.

However, not everyone in this room is talking to everyone else. There's multiple conversations going on.

These conversations need to be unique amongst themselves. This would prevent a duplicate conversation ID being started, and the site collecting all statements which don't belong to that person.

Or, in graphical representation:

----------------------------------------------
| MessageID | ConvoID | Sender | Recipients | etc...
----------------------------------------------
|    1      |    1    |   A    |     B      |
----------------------------------------------
|    2      |    1    |   B    |     A      |
----------------------------------------------
|    3      |    2    |   C    |     D      |
----------------------------------------------
|    4      |    1    |   A    |     B      |
----------------------------------------------
|    5      |    2    |   D    |     C      |
----------------------------------------------
|    6      |    1    |   B    |     E      |
----------------------------------------------
|    7      |    3    |   E    |     F      |
----------------------------------------------

You can actually see the conversations that are taking place here... A talked to B (ID 1), who replied back (ID 2) at around the same time C started a new conversation (CID 2) with D (ID 3).

A finally gets back to B about something (ID 4) and D eventually response to C's earlier inquiry (ID 5). B then talks to E about the same thing he was talking with A about (CID 1) before E turns right around and connects with F to start a completely new conversation.

If this has read like the steps which occur prior to the immediate termination of an employee, it wasn't intended that way, but you're not alone.

So you can see that every DB entry has a unique ID (MessageID), but these messages need to be easily collated together.

The solution I'm seeking is something that allows the DB to create a new and unique "ConvoID". This is why we can't auto-increment, or why we can't force uniqueness on the data set. Duplicates must occur, by nature of what this column is doing, but auto-increment would do, perhaps, the exact opposite of what it is i'm seeking for.

Any help that could point me in the right direction would be significantly appreciated.

Thanks!

  • 写回答

1条回答 默认 最新

  • doueta6642 2012-01-16 07:12
    关注

    You could normalize the design by adding a Conversations table. The table would have its own auto-incrementing column. Whenever a new conversation is started, you add a row to Conversations, and use its identifier as ConvoID.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大