简体   繁体   中英

Designing a database with relational tables in MySQL using Phpmyadmin

I need tips when it comes to designing tables in a database. I am designing an employee meal system that monitors and processes meal logs of employees (like an attendance) My problem is here, I have 2 tables: The employee_table and the log_table. The employee table contains basic employee information and it has a unique key (not a primary one) which is employee_number. And then, there's another table, log_time, which contains the swipe data of the employees. Now, the two tables contain and employee_number column. How do I make relation out of them? Can I bind them together so that when I call for the employee_number column on the log_time it will get the basic information of the employee on the other table as well? Sorry because I'm having a hard time when it comes to designing a database.

SQL syntax for a relation might look something like this:

CREATE TABLE employee_table(
    FOREIGN KEY (employee_number) REFERENCES employees(number),
    ...other stuff...
 )

With another table that looks like

CREATE TABLE employees(
    number INT(10) NOT NULL
)

Here's a great site on SQL foreign keys: http://www.sitepoint.com/mysql-foreign-keys-quicker-database-development/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM