Discussion on the primary key of the data table

  • Regarding the naming method of the database auto-incrementing primary key, do you use ID? Or use the table name + ID method (eg: order_id)?
  • It depends on the situation, as long as it is not a keyword, keep a unified style
  • For example, the key_id we use uniformly
  • I use id, because the orm framework sees the id and immediately becomes the id without setting anything
  • Anyway, write sql later, not the table name.id
  • id is the keyword oracle to report an error
  • pk_id used
  • Ali specification mandates the use of ID, I don't know why - -#
  • How good is the id of Ali mysql, why do you have to add a prefix. .
  • It seems that jfinal defaults to id too
  • Now we use the form of table name + id, but I don't know what's wrong?
  • But look at Ali's development manual and say to use pk_id and then use it
  • It doesn't matter what you use, just unify your own style
  • Rules can be specified by themselves
  • Joint query is a big problem.
  • t1.id = t2.t1_id
  • Why not define a unique id in the first place. There are more trouble spots in the back.
  • Why do we need a unique id... If t2 stores the primary key of t1 as a foreign key, how can I write two t1_ids?
  • How clear is the table name.id?
  • If you think too much, if he uses m3u8 for 3 terminals, it can easily come out.
  • "fuchuan 11:14:16 Why do you need a unique id... If t2 stores the primary key of t1 as a foreign key, how do you write two t1_ids? I don't understand, the primary key name of t1 is t1_id, and it is also this name in other table references, no There will be two. The unique field name is beneficial, both are called id, it is very clear to see, the joint operation is not clear, and the chance of being used indiscriminately when encountering inexperienced people is high.
  • We have measured this problem and used id as the primary key name of all tables, but in the actual development process, we found that it is not the best choice. Finally, all changed to a unique name. Of course, the development framework is different, the way is different, maybe the id is the best for you.
  • In the case of a lot of related queries, it is better to use a unique name instead of simply using the ID directly.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324850240&siteId=291194637