0

My case is, I have some tables from prev developers, contain id and name. The id is not auto-increment (the value is something like A0001) and also CHANGEABLE. I've no idea, why or what reason behind this changeable-ID.

I just wonder what if a table have 2 IDs? I consider to make the current id, as just 'unique code' and add 1 more field, called id, the-auto-increment-and-fix one. So, I need some considerations about this thought. I still feel 'weird' about having 2 ids inside a table >.<

Thank you in advance.

thom
  • 149
  • 13

3 Answers3

1

Yes a table can have more than one key. MAke the the autoincrement column to be the primary key, as well the changeable field to be a key, which will contain unique values

Sashi Kant
  • 13,277
  • 9
  • 44
  • 71
1

You probably have to drop the idea that the existing 'id' is the id, but rather a label. Now you can add a real autoincrementing 'id' and use this to identity the tuples in the table.

I would keep the 'label' unique however.

dmaij
  • 1,017
  • 7
  • 15
  • -1: Having a [`string` field as a primary key is perfectly valid](http://stackoverflow.com/a/517591/1192381). – J.A.I.L. Dec 04 '12 at 13:30
  • @J.A.I.L. You are correct, but having a string or an int is not the issue. Please read before commenting. – dmaij Dec 04 '12 at 13:42
0

No, it's not weird; you can consider that the single ID is the concatenation of both of them.

J.A.I.L.
  • 10,644
  • 4
  • 37
  • 50
  • @j-a-i-l SO the ID is still 'changeable'. Is it not weird also to have a changeable ID as an ID? – thom Dec 04 '12 at 13:08
  • @thom There is no problem, as long as it is still unique and not null. – J.A.I.L. Dec 04 '12 at 13:23
  • @thom (you might have some (solvable) dificulties if that `primary key` is referenced as a `foreign key` in other tables). – J.A.I.L. Dec 04 '12 at 13:34