472,364 Members | 1,579 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,364 software developers and data experts.

Multiple auto increments in one column?

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
Jul 19 '05 #1
12 5461
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'.
Jul 19 '05 #2
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'.
Jul 19 '05 #3
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'.
Jul 19 '05 #4
Well (8 hours later) it turns out you can have multiple auto
increments in one column. Heres how...

Create a table with two or more columns. One column will be the auto
increment and the other column will designate which auto increment to
join. These two columns must be primary keys. Another caveat is that
you MUST create the auto increment column AFTER the designater column.
Heres an example...

--> create table test(a int not null, b int auto_increment not null,
primary key(a,b));

--> insert into test values(1);
--> insert into test values(1);
--> insert into test values(1);
--> insert into test values(2);
--> insert into test values(2);
--> insert into test values(2);
--> insert into test values(3);
--> insert into test values(3);
--> insert into test values(3);

--> select * from test;

+---+---+
| a | b |
+---+---+
| 1 | 1 |
| 1 | 2 |
| 1 | 3 |
| 2 | 1 |
| 2 | 2 |
| 2 | 3 |
| 3 | 1 |
| 3 | 2 |
| 3 | 3 |
+---+---+
Jul 19 '05 #5
Well (8 hours later) it turns out you can have multiple auto
increments in one column. Heres how...

Create a table with two or more columns. One column will be the auto
increment and the other column will designate which auto increment to
join. These two columns must be primary keys. Another caveat is that
you MUST create the auto increment column AFTER the designater column.
Heres an example...

--> create table test(a int not null, b int auto_increment not null,
primary key(a,b));

--> insert into test values(1);
--> insert into test values(1);
--> insert into test values(1);
--> insert into test values(2);
--> insert into test values(2);
--> insert into test values(2);
--> insert into test values(3);
--> insert into test values(3);
--> insert into test values(3);

--> select * from test;

+---+---+
| a | b |
+---+---+
| 1 | 1 |
| 1 | 2 |
| 1 | 3 |
| 2 | 1 |
| 2 | 2 |
| 2 | 3 |
| 3 | 1 |
| 3 | 2 |
| 3 | 3 |
+---+---+
Jul 19 '05 #6
Well (8 hours later) it turns out you can have multiple auto
increments in one column. Heres how...

Create a table with two or more columns. One column will be the auto
increment and the other column will designate which auto increment to
join. These two columns must be primary keys. Another caveat is that
you MUST create the auto increment column AFTER the designater column.
Heres an example...

--> create table test(a int not null, b int auto_increment not null,
primary key(a,b));

--> insert into test values(1);
--> insert into test values(1);
--> insert into test values(1);
--> insert into test values(2);
--> insert into test values(2);
--> insert into test values(2);
--> insert into test values(3);
--> insert into test values(3);
--> insert into test values(3);

--> select * from test;

+---+---+
| a | b |
+---+---+
| 1 | 1 |
| 1 | 2 |
| 1 | 3 |
| 2 | 1 |
| 2 | 2 |
| 2 | 3 |
| 3 | 1 |
| 3 | 2 |
| 3 | 3 |
+---+---+
Jul 19 '05 #7
Thanks for responding, I actually needed them to start from 1 so that
when someone views the first message of a message board, the message
starts at 1. It might be a little weird to start a new message board
with a thread starting from 15,234. The solution I posted seems to be
what I needed. What do you think? -Nick
Jul 19 '05 #8
Thanks for responding, I actually needed them to start from 1 so that
when someone views the first message of a message board, the message
starts at 1. It might be a little weird to start a new message board
with a thread starting from 15,234. The solution I posted seems to be
what I needed. What do you think? -Nick
Jul 19 '05 #9
Thanks for responding, I actually needed them to start from 1 so that
when someone views the first message of a message board, the message
starts at 1. It might be a little weird to start a new message board
with a thread starting from 15,234. The solution I posted seems to be
what I needed. What do you think? -Nick
Jul 19 '05 #10
Nick wrote:
Thanks for responding, I actually needed them to start from 1 so that
when someone views the first message of a message board, the message
starts at 1. It might be a little weird to start a new message board
with a thread starting from 15,234. The solution I posted seems to be
what I needed. What do you think? -Nick


What ever works for you ;)

But if you print the numbers using a programming language, you don't
have to print the number you have in your variable. You can always take
something of it, or even use complitely different numbers.

So instead of printing the id value, you could just do something like:
for( i = 1; i < amount_of_messages; i++ )
{
print "messagenumber: " + i + "\n";
}

But yes, your solution it good also, perhaps even better if it doesn't
cause too much delay.
Jul 19 '05 #11
Nick wrote:
Thanks for responding, I actually needed them to start from 1 so that
when someone views the first message of a message board, the message
starts at 1. It might be a little weird to start a new message board
with a thread starting from 15,234. The solution I posted seems to be
what I needed. What do you think? -Nick


What ever works for you ;)

But if you print the numbers using a programming language, you don't
have to print the number you have in your variable. You can always take
something of it, or even use complitely different numbers.

So instead of printing the id value, you could just do something like:
for( i = 1; i < amount_of_messages; i++ )
{
print "messagenumber: " + i + "\n";
}

But yes, your solution it good also, perhaps even better if it doesn't
cause too much delay.
Jul 19 '05 #12
Nick wrote:
Thanks for responding, I actually needed them to start from 1 so that
when someone views the first message of a message board, the message
starts at 1. It might be a little weird to start a new message board
with a thread starting from 15,234. The solution I posted seems to be
what I needed. What do you think? -Nick


What ever works for you ;)

But if you print the numbers using a programming language, you don't
have to print the number you have in your variable. You can always take
something of it, or even use complitely different numbers.

So instead of printing the id value, you could just do something like:
for( i = 1; i < amount_of_messages; i++ )
{
print "messagenumber: " + i + "\n";
}

But yes, your solution it good also, perhaps even better if it doesn't
cause too much delay.
Jul 19 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Nick | last post by:
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' ,...
4
by: Olafur | last post by:
Hello all, I am a beginner with mysql, however installation was fine no problems and I have been trying the Consol Center trying to create new tables. I get two errors I can't get rid of. ...
3
by: Smitro | last post by:
Hey, I have a site that is about to go into production and it has a couple of tables that it uses that could get quite large once in full swing, most of them have a column called "id" and it...
2
by: Mike N. | last post by:
Hello- I have a database that uses an auto number field type that goes out of sync periodically. My customer gets a "cannot add record, number already in use" error message. I dump the records...
1
by: .Net Newbie | last post by:
I am relatively new to .Net and have been coding an intranet site for my employer for a couple of months. I am currently stuck coding in a text-editor called EditPlus without access to the VS.Net...
6
by: Alpha | last post by:
I retrieve a table with only 2 columns. One is a auto-generated primary key column and the 2nd is a string. When I add a new row to the dataset to be updated back to the database. What should I...
0
by: .Net Newbie | last post by:
I am relatively new to .Net and have been coding an intranet site for my employer for a couple of months. I am currently stuck coding in a text-editor called EditPlus without access to the VS.Net...
3
by: cmk128 | last post by:
Hi I want to select a single row called "row1" but let mysql auto append a NON-exist column call "row2" of it. And i want that non-exist column be auto-increment. how to? If i "select row1...
52
by: MP | last post by:
Hi trying to begin to learn database using vb6, ado/adox, mdb format, sql (not using access...just mdb format via ado) i need to group the values of multiple fields - get their possible...
2
by: paulyXvpf | last post by:
Hi All, FACTS: > I've created a VB.NET 2005 form, with a SQL Server 2000 backend > The form has about 30 fields that populate 30 columns in the SQL database > The form has mostly text feilds,...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.