Special Auto Increment

Hello guys and girls, here is a question I hope you can answer for me.

to avoid that id’s from diffrent tables would end up with the same number I would like a special start to all my diffrent auto incremented rows, as I understand it

ALTER TABLE sometable AUTO_INCREMENT = 1000

like this one can only push forward it to a certain number I would like a unique start to all my autoincemrented stuff like 6666-00 for comment tables and 7777-00 for user tables…

example:

6666-0011

6666-0056

6666-00132

6666-00685 and so on.

Is this possible with SQL?
thanks for any help

No, uniquely identify an id would be done like this: table.id
Its not a problem for the same id to exist in different tables

I know that there is no real problem with having the same id, but I do think that a id IS a Unique identifier for that row and when comparing tables to extract information having two exact same “unique identifier” seems wrong.
So there is no other way for autoincrement to count then 1, 2 , 3 and up or 1000,1001,1002 and up or 1212,1213,1214 and up etc ?

It’s not. Unless you have a very good reason why they should be unique across different tables?

So there is no other way for autoincrement to count then 1, 2 , 3 and up or 1000,1001,1002 and up or 1212,1213,1214 and up etc ?

Well, you could give all tables a composite primary key, with the first column a ‘table identifier’, and the second column the usual autoincremental id. But IMO that would be useless and needlessly complicated, because you’ll always know where you’re getting your data from anyway, so you might as well display the table name together with the id if that’s what you need.

ok looking for a tip.

Let’s say I have 3 tables.

Comments table

Blog Post table

Idea Post table

When I make a Blogpost it gets a unique indentifier 1,2,3,4 etc.

When I make a Idea Post it gets a unique indentifier 1,2,3,4 etc.

When one make a comment on BlogPosts or Idea posts the comment will end up in the comment table.

The comment will usethe unique indentifier teing it either to a blog bost or a idea post.

So that is also why I was thinking if I made the unique identifers to 6666-00 or 7777-00 there can never be that they end up with the same number.

Am I approaching this all wrong or? should I just make 4 tables?

Blog Comments table

Blog Post table

Idea Comments table

Idea Post table

I really hope I make sense, for some reason I find it very hard to express what I mean using letters :smiley:

there’s your problem – the comment table should not reference a pair of “either/or” tables with a single foreign key, you would instead use two foreign keys, one to one table, the other to the other table, and one of those foreign keys being NULL on any given row

you might find it easier to have only two tables – one for blogs/ideas, and one for comments

then your “unique across all tables” identifiers problem goes away

in fact, if it were me, i would use only one table for everything

:slight_smile:

a yea that would make it alot easier woulden it :smiley: thanks m8.

Thanks all for the help