一列中有多个自动增量? [英] Multiple auto increments in one column?

查看:56
本文介绍了一列中有多个自动增量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一列中可以有多个自动增量吗?说我

有两张桌子......


1.表''留言板''带字段(''id'',''name'' )


2.表''messagethreads''带字段(''id'',''messagethread'',

''adminboard_id'')


''messagethreads.id''列可以有多个自动增量。

然后我可以轻松查询留言板(SELECT * FROM

messagethreads WHERE messageboard_id = 1 ORDER BY id")。每个线程

将返回从1开始的id。如果MySQL不支持

多个自动增量,我想其他唯一的解决方案是......


- 使用自动增量

列为每个''留言板'创建一个新表,并将它们连接到''messagethreads''进行查询。我想尽可能少地使用




- 使用事务或表锁定来生成自动增量

值。我不想出于性能原因使用它们。


任何人都有更好的解决方案吗?我确定已经完成了吗?谢谢!


-Nick

解决方案

Nick写道:

是吗可能在一列中有多个自动增量?说我有两张桌子......

1.表''留言板''带字段(''id'',''name'')

> 2.表''messagethreads''带字段(''id'',''messagethread'',
''messageboard_id'')

''messagethreads.id''列可以有多个自动增量。
然后我可以使用(SELECT * FROM
messagethreads WHERE messageboard_id = 1 ORDER BY id)轻松查询留言板。每个线程将从数字1开始返回一个id。如果MySQL不支持多个自动增量,我想其他唯一的解决方案是......




为什么他们需要从1号开始?如果它们从543或43645开始,它会有什么区别

?它们仍然是正确的顺序和

你只会获得正确留言板的消息线程,因为你使用''$ message where里面的消息板'='''。


Nick写道:

是否可以在一列中有多个自动增量?说我有两张桌子......

1.表''留言板''带字段(''id'',''name'')

> 2.表''messagethreads''带字段(''id'',''messagethread'',
''messageboard_id'')

''messagethreads.id''列可以有多个自动增量。
然后我可以使用(SELECT * FROM
messagethreads WHERE messageboard_id = 1 ORDER BY id)轻松查询留言板。每个线程将从数字1开始返回一个id。如果MySQL不支持多个自动增量,我想其他唯一的解决方案是......




为什么他们需要从1号开始?如果它们从543或43645开始,它会有什么区别

?它们仍然是正确的顺序和

你只会获得正确留言板的消息线程,因为你使用''$ message where里面的消息板'='''。


Nick写道:

是否可以在一列中有多个自动增量?说我有两张桌子......

1.表''留言板''带字段(''id'',''name'')

> 2.表''messagethreads''带字段(''id'',''messagethread'',
''messageboard_id'')

''messagethreads.id''列可以有多个自动增量。
然后我可以使用(SELECT * FROM
messagethreads WHERE messageboard_id = 1 ORDER BY id)轻松查询留言板。每个线程将从数字1开始返回一个id。如果MySQL不支持多个自动增量,我想其他唯一的解决方案是......




为什么他们需要从1号开始?如果它们从543或43645开始,它会有什么区别

?它们仍然是正确的顺序和

你只会获得正确留言板的消息线程,因为你使用''$ message where里面的消息板'='''。


Is it possible to have multiple auto increments in one column? Say I
have two tables...

1. table ''messageboards'' with fields (''id'' , ''name'')

2. table ''messagethreads'' with fields (''id'' , ''messagethread'' ,
''messageboard_id'')

The ''messagethreads.id'' column could have multiple auto increments.
Then I could easily query a messageboard with ("SELECT * FROM
messagethreads WHERE messageboard_id = 1 ORDER BY id"). Each thread
would return an id starting from number 1. If MySQL does not support
multiple auto increments, I guess the only other solutions are...

- Create a new table for every ''messageboard'' with an auto increment
column and join them to ''messagethreads'' for a query. Id like to use
as few tables as possible though.

- Use transactions or table locking to generate the auto increment
value. Id like to not use either for performance reasons.

Anyone have a better solution? Im sure its been done? Thanks!

-Nick

解决方案

Nick wrote:

Is it possible to have multiple auto increments in one column? Say I
have two tables...

1. table ''messageboards'' with fields (''id'' , ''name'')

2. table ''messagethreads'' with fields (''id'' , ''messagethread'' ,
''messageboard_id'')

The ''messagethreads.id'' column could have multiple auto increments.
Then I could easily query a messageboard with ("SELECT * FROM
messagethreads WHERE messageboard_id = 1 ORDER BY id"). Each thread
would return an id starting from number 1. If MySQL does not support
multiple auto increments, I guess the only other solutions are...



Why would they need to start from number 1? What difference does it make
if they start from 543 or 43645? They will still be in correct order and
you will only get messagethreads for the correct messageboard, since you
use ''where messageboard_id = 1''.


Nick wrote:

Is it possible to have multiple auto increments in one column? Say I
have two tables...

1. table ''messageboards'' with fields (''id'' , ''name'')

2. table ''messagethreads'' with fields (''id'' , ''messagethread'' ,
''messageboard_id'')

The ''messagethreads.id'' column could have multiple auto increments.
Then I could easily query a messageboard with ("SELECT * FROM
messagethreads WHERE messageboard_id = 1 ORDER BY id"). Each thread
would return an id starting from number 1. If MySQL does not support
multiple auto increments, I guess the only other solutions are...



Why would they need to start from number 1? What difference does it make
if they start from 543 or 43645? They will still be in correct order and
you will only get messagethreads for the correct messageboard, since you
use ''where messageboard_id = 1''.


Nick wrote:

Is it possible to have multiple auto increments in one column? Say I
have two tables...

1. table ''messageboards'' with fields (''id'' , ''name'')

2. table ''messagethreads'' with fields (''id'' , ''messagethread'' ,
''messageboard_id'')

The ''messagethreads.id'' column could have multiple auto increments.
Then I could easily query a messageboard with ("SELECT * FROM
messagethreads WHERE messageboard_id = 1 ORDER BY id"). Each thread
would return an id starting from number 1. If MySQL does not support
multiple auto increments, I guess the only other solutions are...



Why would they need to start from number 1? What difference does it make
if they start from 543 or 43645? They will still be in correct order and
you will only get messagethreads for the correct messageboard, since you
use ''where messageboard_id = 1''.


这篇关于一列中有多个自动增量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆