I am designing the database (MySQL) in which I have two tables Employees and Guests as following :
CREATE TABLE employee (
`EMP_ID` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`FIRST_NAME` VARCHAR(8) NOT NULL,
`MID_NAME` VARCHAR(11),
`LAST_NAME` VARCHAR(8) NOT NULL,
`BIRTHDAY` DATE,
`COUNTRY_ID` INT,
`NAT_ID` VARCHAR(8) NOT NULL,
`ID_EXP_DATE` DATE,
`ID_TYPE` VARCHAR(8) NOT NULL,
`Mobile` VARCHAR(8) NOT NULL,
`PHONE` VARCHAR(8) NOT NULL,
`EMAIL` VARCHAR(27) NOT NULL,
`DEPT_ID` TINYINT NOT NULL references DEPARTMENT (ID),
`POSITION` VARCHAR(20),
`EMP_TYPE` TINYINT NOT NULL references EMP_TYPES (type),
`JOINDATE` DATE,
`SALARY` MEDIUMINT DEFAULT 0 ,
`WORKEMAIL` VARCHAR(30),
`MARITALSTAT` VARCHAR(7),
`EMERGCONTACT` VARCHAR(22),
`EMERG_CONT_PHN` VARCHAR(11),
`GENDER` VARCHAR(6),
`RESUMEURL` VARCHAR(60),
`RELIGION` VARCHAR(11),
PRIMARY KEY (`EMP_ID`));
CREATE TABLE Guest (
`guest_ID` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`FIRST_NAME` VARCHAR(8) NOT NULL,
`MID_NAME` VARCHAR(11),
`LAST_NAME` VARCHAR(8) NOT NULL,
`BIRTHDAY` DATE,
`COUNTRY_ID` INT,
`NAT_ID` VARCHAR(8) NOT NULL,
`ID_EXP_DATE` DATE,
`ID_TYPE` VARCHAR(8) NOT NULL,
`Mobile` VARCHAR(8) NOT NULL,
`PHONE` VARCHAR(8) NOT NULL,
`EMAIL` VARCHAR(27) NOT NULL,
`WORKEMAIL` VARCHAR(30),
`MARITALSTAT` VARCHAR(7),
`EMERGCONTACT` VARCHAR(22),
`EMERG_CONT_PHN` VARCHAR(11),
`GENDER` VARCHAR(6),
`RELIGION` VARCHAR(11),
..................................// More attributes specific for guest table
PRIMARY KEY (`Guest_ID`));
Since both of the tables have auto generated primary keys and it would not be appropriate if they share primary key from person. would it be a good idea to create a table named person with all the common attributes and two child tables as Employee and Guest?
and what would be the best practice to implement this?
Thank You,
There are some things to consider:
Can an Employee be a Guest or vice versa?
How to compare them?
If this plays a role for your application, i´d consider a ParentTable, because so you can easily figure out, if an Employee is also a Guest or not. So you can easily compare them.
On the other hand, you could do a 3rd Option:
A Table called Personal Information.
An Employee has an Reference to this, Guests also.
If an Employee and an Guest both refeer to the same entry, you know they are the same person.
Schema:
yes the schema is like:
Table:
PersonalInformation
ID (Primary Key, auto inc)
And put all your information here
Table Employee
ID (Primary Key, auto inc int)
PersonalInformation_ID (ForeignKey to PersonalInformation.ID)
Add your Employee specific columns here
Table Guest
ID (Primary Key, auto inc int)
PersonalInformation_ID (ForeignKey to PersonalInformation.ID)
Add your Guest specific columns here
Hope this helps you implement it, otherwise ask again.