Hello lz, my personal idea is this. Put all companies in a table and add a mark to indicate which company they belong to. Put all departments in a table and add a mark to indicate which company they belong to. If the next level is the position table (not specified in the original poster's question), then add a mark to store the department id in the department table. If the next level is the user table, then the json data of the ID of the user storage department is converted into a string and stored in a column.
When you are in a hurry, your thinking is not careful. If there is anything unreasonable, please point it out
Generally I will build the table like this companies company table
company_id primary key, auto-increment company_name company name
departments department table
department_id department id primary key, auto-increment department_name department name company_id foreign key, related to the company table
jobs job list
job_id job id, primary key, auto-increment job_name job name department_id department id
= . =In this way, the relationship will be established layer by layer. . There are not many write statuses in these tables, but many read statuses. If you want to count the number of positions and departments, you can open a table such as company_status
Company table comapny
Department table department
User table user
User company department relationship table user_company_department_relation
Hello lz, my personal idea is this. Put all companies in a table and add a mark to indicate which company they belong to. Put all departments in a table and add a mark to indicate which company they belong to.
If the next level is the position table (not specified in the original poster's question), then add a mark to store the department id in the department table.
If the next level is the user table, then the json data of the ID of the user storage department is converted into a string and stored in a column.
When you are in a hurry, your thinking is not careful. If there is anything unreasonable, please point it out
Generally I will build the table like this
companies company table
company_id primary key, auto-increment
company_name company name
departments department table
department_id department id primary key, auto-increment
department_name department name
company_id foreign key, related to the company table
jobs job list
job_id job id, primary key, auto-increment
job_name job name
department_id department id
= . =In this way, the relationship will be established layer by layer. .
There are not many write statuses in these tables, but many read statuses. If you want to count the number of positions and departments, you can open a table such as company_status
Add the foreign key of the company table to the department table