Suppose, you are working on a project where the database has two tables, such as student and clazz, structured like below:
|
CREATE TABLE `clazz` ( `id` int(11) NOT NULL, `name` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `student` ( `id` int(11) NOT NULL, `name` varchar(255) DEFAULT NULL, `clazz_id` int(11) DEFAULT NULL, PRIMARY KEY (`id`), FOREIGN KEY (`clazz_id`) REFERENCES `clazz` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; |
As you can see, the clazz table has columns id and name with the primary key id. Student table has columns id, name… Read More