normalization of database

陌路散爱 提交于 2019-12-25 02:24:48

问题


I would like to ask about a question relating to normalization.

I have 2 PKs, VIN and Reg_no. VIN is the Vehicle ID Number and Registration number is the car plate number. I have an attribute called current odometer. Does it have a partial dependency or a full dependency on the 2 PKs?


回答1:


I have 2 PKs, VIN and Reg_no. VIN is the Vehicle ID Number and Registration number is the car plate number.

You have two candidate keys. VIN is unique; the plate number is also probably unique. (But it depends on your application.)

Any key can consist of multiple columns, but you don't have one multi-column key, you have either one key (VIN) or two separate keys (VIN and plate). And there's nothing wrong with that.

I have an attribute called current odometer. Does it have a partial dependency or a full dependency on the 2 PKs?

Regardless of whether you have only one key or two in this table, each key has only one column. Since each possible key has only one column, it's impossible to have a partial key dependency.




回答2:


You probably only need ONE PK. Use the VIN since it's absolutely unique. Registration Number could be "re-used" across states/provinces.

Your "Composite Primary Keys" will be on your join tables where needed.

VEHICLE_TABLE

VIN                  nvarchar(50) [pk]
RegistrationNumber   nvarchar(50)
NumberOfPassengers   int
Make                 nvarchar(20)
Model                nvarchar(20)
Color                nvarchar (20)
Features             nvarchar(MAX)

DRIVER_TABLE

DriverID             int [pk]
Name                 nvarchar(20)
Address              nvarchar(50)
OtherCrap            nvarchar(MAX)

POSITION_TABLE

PositionID           int [pk]
Position             nvarchar(50)

MAINTENANCE_TABLE

MaintenanceID        int [pk]
VIN                  nvarchar(50) [fk - VEHICLE_TABLE.VIN]
Odometer             decimal(9,2)
MaintenanceDate      DateTime

STAFF_TABLE

StaffID              int [pk]
Name                 nvarchar(20)
PositionID           int [fk - POSITION_TABLE.PositionID]

VEHICLE_JOIN_DRIVER_TABLE

VIN                  nvarchar(50) [cpk fk - VEHICLE_TABLE.VIN]
DriverID             int [cpk fk - DRIVER_TABLE.DriverID]

VEHICLE_JOIN_STAFF_TABLE

VIN                  nvarchar(50) [cpk fk - VEHICLE_TABLE.VIN]
DriverID             int [cpk fk - DRIVER_TABLE.DriverID]
StaffID              int [cpk fk - STAFF_TABLE.StaffID]

This answer also attempts to "somewhat" answer your other question.
What is the PK and FK i should assign to my table?



来源:https://stackoverflow.com/questions/12946085/normalization-of-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!