A beginners\' question about foreign key in MySQL.
In w3school it says,
A FOREIGN KEY in one table points to a PRIMARY KEY in another table.<
First of all. Good Question !!
MySql is an RDBMS - Relational DBMS, so all the entities (tables) are related by an column.
EMPLOYEE - EMPID EMPNAME DEPTID
DEPARTMENT - DEPTID DEPTNAME
DEPTID is foriegn key in the EMPLOYEE table and primary key in the DEPARTMENT table.
This relation is imaginary relation of objects just an consideration or kind of designing for structuring data in a easy way to retrieve in future. NOT A PHYSICAL RELATION (because its a programming language)
In order to retrive that data, we need few syntax and described by the Creator of SQL.
SELECT * from EMPLOYEE
SELECT * FROM DEPARTMENT
SELECT * FROM EMPLOYEE WHERE DEPTID = 5
Here we have realted the two tables imaginary for our convinent, but for the required result we used this syntax WHERE DEPTID = 5.