1

I have the following issue. We are currently working on a system for a shuttle service company. Now, part of the entities in the database for this system include numerous lookup tables (such as vehicle_type, employee_status, etc), as well as some other tables, such as vehicle and vehicle_service log.

Now the issue we as a team are having is that we cannot agree on what the logical relationship cardinalities between entities should be. The two main problem relationships include the tables defined as 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 the user types - employee
 or consultant' AUTO_INCREMENT=1 ;

which is linked to

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 
to check access level, type of user, etc. ' AUTO_INCREMENT=1 ;

The user table includes other irrelevant data. So the issue here is that I say (because MySQL Workbench reverse engineered it that way and it makes more sense) that the relationship should be 1-many, while another team member says that it should be 0-many (because some records may exist in the user_type table that aren't used in the user table)

The other table relationship we are having words about are defined as 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, with some other columns not relative to the question. This links with

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 all services 
to vehicles' AUTO_INCREMENT=1 ;

Should this be 1-many or 0-many because a vehicle may not yet go in for a service? According to me it should be 1-many, but I don't know if this works logically.

We are all very confused about this whole logical modelling thing, so any help would be much appreciated!

I figured it would be easier for me to create the DB first and then reverse engineer it to a physical model, but never though about logical.

4

1 回答 1

1

如果它是可选的,则从零到多。例如,销售代表将有零个或多个客户。这是为什么?因为如果有一个新的销售代表,那么这意味着他/她没有客户可以开始,除非他/她当然承担已辞职的销售代表的账户。

另一方面,一个或多个是强制性的。例如,具有订单日期的订单和订购的客户应在订单详细信息表中至少有一条记录。假设客户在 2013 年 4 月 22 日最后订购了一台平板电脑,那么他/她将拥有:

 Order table
 ----------------------------------------
 Orderid.  OrderDate. Customermnum
 ----------------------------------------
  1.       04/22/2013 101

 Order detail table
 ----------------------------------------
 Orderid.  Productid.  Qty.   quotedprice
 ----------------------------------------
  1.       T101       1       500

因此,在您的情况下,User 到 UserType 是 1 到 0 或很多,因为用户类型可能尚未被任何用户使用。

现在,vehicle to service 它也是 1 比 0 或许多,因为车辆可能不一定已经完成服务。

于 2013-04-25T13:36:30.293 回答