SQL Relationship Cardinality in Logical Design -


i have following issue. working on system shuttle service company. now, part of entities in database system include numerous lookup tables (such vehicle_type, employee_status, etc), other tables, such vehicle , vehicle_service log.

now issue team having cannot agree on logical relationship cardinalities between entities should be. 2 main problem relationships include tables defined follows:

create table if not exists `user_type` (   `type_id` tinyint(4) not null auto_increment,   `description` varchar(200) not null,   primary key (`type_id`) ) engine=innodb  default charset=latin1 comment='store user types - employee  or consultant' auto_increment=1 ; 

which linked

create table if not exists `user` (   `user_id` int(11) not null auto_increment,   `username` varchar(100) not null,   `password` varchar(100) not null,   `user_type` tinyint(4) not null,   primary key (`user_id`),   key `user_type` (`user_type`),   key `username` (`username`),   key `login` (`username`,`password`) ) engine=innodb  default charset=latin1 comment='table used when logging in  check access level, type of user, etc. ' auto_increment=1 ; 

the user table includes other irrelevant data. issue here (because mysql workbench reverse engineered way , makes more sense) relationship should 1-many, while team member says should 0-many (because records may exist in user_type table aren't used in user table)

the other table relationship having words defined follows:

create table if not exists `vehicle` (   `vehicle_id` int(11) not null auto_increment,   `registration_number` varchar(10) not null,   primary key (`vehicle_id`),   unique key `registration_number` (`registration_number`), ) engine=innodb  default charset=latin1 comment='actual vehicle information'  auto_increment=1 ; 

again, other columns not relative question. links

create table if not exists `service_log` (   `id` int(11) not null auto_increment,   `vehicle_id` int(11) not null,   `description` text not null,   `date` date not null,   `cost` double not null,   primary key (`id`),   key `vehicle_id` (`vehicle_id`) ) engine=innodb default charset=latin1 comment='store records of services  vehicles' auto_increment=1 ; 

should 1-many or 0-many because vehicle may not yet go in service? according me should 1-many, don't know if works logically.

we confused whole logical modelling thing, appreciated!

i figured easier me create db first , reverse engineer physical model, never though logical.

zero many if optional. example sales rep have 0 or many customer. why that? because if there new sales rep mean he/she has no customer begin unless of course he/she assume accounts of resigned sales rep.

on other hand 1 or many mandatory. example order has order date , customer ordered should have @ least 1 record on order detail table. let's customer ordered tablet last 04/22/2013 he/she have:

 order table  ----------------------------------------  orderid.  orderdate. customermnum  ----------------------------------------   1.       04/22/2013 101   order detail table  ----------------------------------------  orderid.  productid.  qty.   quotedprice  ----------------------------------------   1.       t101       1       500 

so, in case user usertype 1 0 or many beacause user type may have not been used user yet.

now, vehicle service 1 0 or many since vehicle may not have service done yet.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -