R
R
Ruslan Samara2018-11-11 11:18:29
MySQL
Ruslan Samara, 2018-11-11 11:18:29

Do I need an id field with primary key if there is id_cat to join mysql tables?

You need to create several tables and link them together.
Do I need to create a separate id field with a primary key in each table and use an increment for the field, as well as have a separate id field (for example, id_category, in general there are more fields to link with other tables).
And is it necessary to use 2 id fields for child tables too?
The base will be very large and will expand very quickly.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
1
1001001, 2018-11-11
@lkmrus

I doubt that id_category will ensure the uniqueness of records for a given table.
Naturally, a primary key is needed, whether it will be an auto-increment or not is up to you to decide.

A
Antony Tkachenko, 2018-11-11
@LemonFox

It's not entirely clear from your question about the structure of the tables.
In general, for link tables, you can make composite keys for two or more fields.
For example, there is a table, category, product and a table of relations product_category with fields category_id, product_id, then the key will look like this - PRIMARY KEY(category_id, product_id).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question