mysql - Database design naming: should use "id" or "table_name" + "id"? -


So, there is an ID for each table, usually it is not an ET (11) auto ink, tap.

When I was in school, I named it primarily as ID,

However, when I face more complex database designs, I think that If I use "ID", then I have to do more

For example, a customer is a "customer", "customer_group"

, so I am a customer and its Here's how to get the customer-group information:

  SELECT * Customers from JOIN customer_group at customer.group_id = customer_g Please note that two IDs will return, if I want to separate them, then I need to:  
  select customer Id as cid, customer_group_id AS cgid, customer.NAME, ....... customer.group_id = customer_group.id   

on JOIN customer_group by customer and it becomes very difficult If the query is long, I wonder what is the practice in id naming, should I use table_name + "id" for the name? Thanks

We can do something like this, making it less difficult and more readable.

  select c.id as cid, customer_group_id as cgid, c.NAME, ....... customer C-join customer_group cg ON c.group_id = cg.id   

In the case of ID naming, the best practice of ID is opinion based, or the implementation standard is based. The profit on each method varies in every situation.

Generally, id should be an x table id but when used in another table , It calls the y table as a foreign key, it will be X_ID

, so it is clear in the Y table This will define the naming conventions of the id

of the X_ID X table defined by the convenience of the developers, then this car The system is created and later it will become standard, but it also affects us with changes in the development environment.

I would suggest that whether its business project chooses the naming convention according to the standard .

If Personal Projects, Your Habits ..

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -