Hi
I am currently designing a database that had employees, addresses, corporate and residential users. Here are some of scenarios:
- a user can belong to multiple (many) companies
- a user can belong to several (many) residences
- a user can be an employee
- residential addresses dont have a name they have only addresses
- coporation have distinct categorizations on how they are broken down i.e. departments, buildings, floor, post office box …
- all types of users have multiple forms of communications ie. land phone, cell phone, email, messaging…
So do you think that this is a needlessly complex design or appropriate?
- Any of the NULL fields can be left blank; the communications table will almost always have some of the fields blank.
- The company is currently linked as a lookup from the addresses table (a bit cludgy do you think?)
- a mapping table user2communications2addresses brings all the related data together and I think fufills all of the many to many relationships that I refered to above?
Addresses:
CREATE TABLE `users`.`addresses` (
`address_id` int(11) NOT NULL,
`address_type_id` int(11) NOT NULL,
`intended_use` varchar(150) default NULL,
`street_number` int(11) NOT NULL,
`street_name` varchar(150) NOT NULL,
`street_direction` varchar(2) default NULL,
`post_office_box` int(1) default NULL,
`locality` varchar(20) default NULL,
`city` varchar(100) NOT NULL,
`province` varchar(100) NOT NULL,
`post_code` varchar(20) NOT NULL,
`region` varchar(150) default NULL,
`company_id` int(11) default NULL,
`assembled address block` text,
PRIMARY KEY (`address_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Companies:
CREATE TABLE `users`.`companies` (
`company_id` int(11) NOT NULL,
`company_name` varchar(150) NOT NULL,
`department_name` varchar(100) NOT NULL,
`building` varchar(100) NOT NULL,
`floor` varchar(100) default NULL,
`mail_stop` varchar(100) default NULL,
PRIMARY KEY (`company_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Users:
CREATE TABLE `users`.`users` (
`uid_number` int(11) NOT NULL,
`uid` varchar(128) NOT NULL,
`password` char(64) NOT NULL,
`salutation` varchar(6) default NULL,
`first_name` varchar(150) default NULL,
`middle_names` varchar(250) default NULL,
`last_name` varchar(150) default NULL,
`language` varchar(100) default NULL,
`written_greeting` varchar(150) default NULL,
`verbal_greeting` varchar(150) default NULL,
`degree` varchar(150) NOT NULL COMMENT 'such as M.S., Ph. D, and other honorary titles',
PRIMARY KEY USING BTREE (`uid_number`,`uid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
communication_types:
CREATE TABLE `users`.`communication_types` (
`communication_type_id` tinyint(4) NOT NULL auto_increment,
`communication_type` varchar(150) NOT NULL,
`communication_category` varchar(150) NOT NULL default 'phone',
PRIMARY KEY USING BTREE (`communication_type_id`)
) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=utf8;
communications:
CREATE TABLE `users`.`communications` (
`communication_id` int(11) NOT NULL default '0',
`communication_type_id` tinyint(4) NOT NULL default '0',
`phone_number` int(11) default NULL,
`internal_extension` smallint(6) default NULL,
`secondary_dialing_instructions` text,
`complete_foreign_dialing_sequence` text,
`complete_local_dialing_sequence` text,
`text_handle` varchar(250) default NULL,
`email_address` varchar(250) default NULL,
`is_primary_email_address` tinyint(1) default NULL,
`url` varchar(250) default NULL,
PRIMARY KEY USING BTREE (`communication_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
user2communications2addresses:
CREATE TABLE `users`.`user2communications2addresses` (
`uid_number` int(11) NOT NULL,
`communication_id` int(11) NOT NULL,
`addresses_id` int(11) NOT NULL,
PRIMARY KEY USING BTREE (`uid_number`,`communication_id`,`addresses_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
Your thoughts on this design are appreciated.
Regards,
Steve