Step 2 - The Physical Database Model
The physical model of our database does not exactly correspond to the logical model used by the application. Although each student and teacher object will have an address, for instance, these details will be stored in a separate table. This is done so that the less-used columns are kept separate to the commonly used fields, thereby maximising the throughput for queries that don't need any address details. The actual database layout consists of the five tables shown here:
CREATE TABLE `students` (
`id` int(11) NOT NULL auto_increment,
`firstname` varchar(255) NOT NULL,
`surname` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
CREATE TABLE `teachers` (
`id` int(11) NOT NULL auto_increment,
`firstname` varchar(255) NOT NULL,
`surname` varchar(255) NOT NULL,
`email` varchar(255) default NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
CREATE TABLE `subjects` (
`id` int(11) NOT NULL auto_increment,
`Subject` varchar(255) NOT NULL,
`teacherId` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
CREATE TABLE `enrolments` (
`id` int(11) NOT NULL auto_increment,
`studentId` int(11) NOT NULL,
`subjectId` int(11) NOT NULL,
`examResult` tinyint(4) default NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
CREATE TABLE `address` (
`id` int(11) default NULL,
`line1` varchar(255) NOT NULL,
`line2` varchar(255) default NULL,
`suburb` varchar(255) NOT NULL,
`state` varchar(50) NOT NULL,
`postcode` varchar(50) NOT NULL,
`email2` varchar(255) default NULL,
`phone` varchar(255) default NULL,
`mobile` varchar(255) default NULL,
`studentId` int(11) default NULL,
`teacherId` int(11) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1