我正在设置资产跟踪数据库。黑莓,电脑,服务器,显示器,扬声器,键盘,鼠标,椅子,书桌,立方体,立方体墙壁,打印机,冰箱,微波炉等各种资产都有所不同。 该范围将是我的类别表:
create table AssetManagement.zCategory(
zCategoryId int identity primary key,
CategoryDescription varchar(15) unique not null
)
计算机很容易拥有类别,制造商和型号,但某些资产(椅子或其他)可能只有一个型号。有些人可能只有制造商。
我认为使用良好的数据库设计来强制实施以下内容是一个很好的设计:
因此,虽然模型可能具有已知制造商,但资产可能具有模型或制造商,或两者兼而有之,但它应始终具有类别。
这是我到目前为止所提出的内容,并且我考虑使用触发器强制执行直接外键不会
create table AssetManagement.zModel(
zModelId int identity primary key,
zModelDescription varchar(15) unique not null,
zAssetCategoryId int not null references AssetManagement.zAssetCategory(zAssetCategoryId)
)
create table AssetManagement.zManufacturer(
zManufacturerId int identity primary key,
zManufacturerDescription varchar(15) unique not null
)
create table AssetManagement.zProduct
(
zProductId int identity primary key,
zProductDescription varchar(35),
zAssetCategoryId int references AssetManagement.zAssetCategory(zAssetCategoryId),
zModelId int references AssetManagement.zModel(zModelId),
zManufacturerId int references AssetManagement.zManufacturerId(zManufacturerId)
)
create table Assetmanagement.Asset(
AssetId int identity primary key,
Tag varchar(15),
zProductId int not null references assetmanagement.zProduct,
zLocationId int references assetmanagement.zLocation(zLocationId),
EmployeeId int references assetmanagement.employee(employeeId),
PurchasedDate datetime,
PurchasedBy int references assetmanagement.employee(employeeId),
DisposalDate datetime,
Depreciated float,
AddedBy int references assetmanagement.employee(employeeId),
AddedDate datetime
)
或者错过了船,并且有一种方法可以设计这种方式(在物质表上直接使用modelid,manufactrid和产品类型,同时实施适当的唯一性?
答案 0 :(得分:4)
我会这样做。
基本上,资产就是带有标签的东西。它不包含有关类别,制造商或型号的信息。如果你这样做,你就会对你的数据进行非正规化。它包含Model的外键,即该信息。我认为模型和制造商只不过是自由形式的文本,但在某些情况下,您的要求可能会将其中一个或两个变成表格。
您可以将具有资产的人存储在资产表中,但您没有这样的历史记录(尽管可以使用资产历史记录或审计表来完成)。