I am trying to create a site where users can register and create a profile, so I use two MySQL tables in the database, for example. users and user_profile .
The users table has an auto increment primary key called user_id .
The user_profile table has the same primary key called user_id , but it is not auto increment .
* see note on why I have multiple tables.
When a user subscribes, data from the registration form is inserted into users, then last_insert_id() is entered into the user_id field of the user_id table. I use transactions so this always happens.
My question is, is this bad practice?
Should I have a unique auto increment primary key for the user_profile table, although one user can only have one profile?
Maybe there are other flaws in creating a database like this?
I would appreciate if anyone could explain why this is a problem, or if everything is in order, I would like to make sure my database is as efficient as possible.
Note. . I use separate tables for the user and user_profile, because user_profile contains fields that are potentially null, and will also be requested much more than the user table, due to the data being displayed on the public profile.
Maybe this is also a bad practice, and they should be concentrated in one table?
Alex
source share