I am using PHP and MySQL, i am just wondering which route would be better for performance, The database is going to be constantly growing, but at a relatively slow rate, but for each employee i have to store a decent amount of information, ex:
id
name
address
phone
email
coworkers
pay_rate
notes
tasks
completed_tasks
so I am wondering which is better for my database set-up?
s开发者_运维知识库hould i create a new table for each employee, or should i just create each table link the information accordingly with an id number.
These are should be the tables
EMPLOYEES
id
name
address
phone
email
pay_rate
COWORKERS (this is a link table, tells relationship among employees)
EMPLOYEE.ID (FK)
EMPLOYEE.ID (FK)
NOTES
notes_id
notes
EMPLOYEE.id (FK)
TASKS
task_id
task-details
completed (int or bool)
EMPLOYEE.id (FK)
Do not create new table for each employee. Not recommended.. searches, filtering will be difficult. You should organize data keeping in mind how they are interrelated in terms of mapping e.g. employee set is mapped to notes set in one to many manner.
Also, you should not think too much about what if db starts overflowing. If that time comes, you must be having mutiple billions of rows. And then you may think of a technique to arrange data.
I would definitely do the latter. You don't need to proliferate tables in your database, just add a new record to your employee table for each new employee, and have one-to-many information tracked in other table(s) that index back with an employeeId field (which you'll want to make a foreign key).
You want to make sure your employees table only has employee information, though, and not stuff like 'coworkers'. Use multiple tables to track sets of data with different meanings/purposes/relationships. Relational databases ftw.
精彩评论