0

I am designing a database with multiple tables like users, content, etc. I want to allot id to each row in the tables.

So what are the criteria to generate an unique id for each row in each table. And should I make the id in auto increment mode?

Aditya Borde
  • 1,227
  • 2
  • 12
  • 31
  • Sounds like a good idea, in general. – jarlh Jun 08 '16 at 07:04
  • `Auto increment` is indeed what you need – sagi Jun 08 '16 at 07:07
  • @jarlh What should be the length of the id – Aditya Borde Jun 08 '16 at 07:09
  • Depends on the size of the table. – sagi Jun 08 '16 at 07:10
  • What if it is difficult to determine the size? For instance in my content table, the content will be added frequently – Aditya Borde Jun 08 '16 at 07:14
  • For example Google uses 21 digits for user id. So is it preferable to have a fixed length id like 1000001, 1000002 and so on or normal 1, 2, 3 – Aditya Borde Jun 08 '16 at 07:18
  • How many records do you expect to have in your tables? Sql-Server, MySql, Oracle and probably a lot of other databases int data type can hold values between -2^31 (-2,147,483,648) and 2^31-1 (2,147,483,647). I don't imagine you will need a much bigger number, but if you will you can use BIGINT. – Zohar Peled Jun 08 '16 at 07:38
  • To answer your other question - I think it's better to go with a simple 1, 2, 3... instead of 10000001, 10000002... However most auto-increment columns will enable you to choose a starting number that is bigger then 1, if you want to. – Zohar Peled Jun 08 '16 at 07:41
  • @ZoharPeled what would be the difference in using 1,2,3 or 10000001 as the primary key ? – Parth Kapadia Jun 08 '16 at 07:56
  • no real difference, it's just a personal preference. – Zohar Peled Jun 08 '16 at 08:32

0 Answers0