资产数据库设计问题

时间:2009-12-13 01:26:56

标签: sql database-design schema asset-management

我正在设置资产跟踪数据库。黑莓,电脑,服务器,显示器,扬声器,键盘,鼠标,椅子,书桌,立方体,立方体墙壁,打印机,冰箱,微波炉等各种资产都有所不同。 该范围将是我的类别表:

create table AssetManagement.zCategory(
   zCategoryId int identity primary key,
   CategoryDescription varchar(15) unique not null
   )

计算机很容易拥有类别,制造商和型号,但某些资产(椅子或其他)可能只有一个型号。有些人可能只有制造商。

我认为使用良好的数据库设计来强制实施以下内容是一个很好的设计:

  • 如果Model的制造商已知,
    • 无法使用不同的类别或制造商将相同的型号ID存储在数据库的其他位置
  • 存储在数据库中的资产必须具有类别
  • 在3中的任何一个中使用id来表示'unknown'会不舒服,但可能是必要的)

因此,虽然模型可能具有已知制造商,但资产可能具有模型或制造商,或两者兼而有之,但它应始终具有类别。

这是我到目前为止所提出的内容,并且我考虑使用触发器强制执行直接外键不会

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和产品类型,同时实施适当的唯一性?

1 个答案:

答案 0 :(得分:4)

我会这样做。

  • 资产(id,model_id,asset_tag,created_date);
  • 型号(id,category_id,制造商,型号,描述);
  • 类别(id,name);
  • 人(id,title,given_names,surname,job_title,...);
  • 分配(id,asset_id,person_id,start_date,end_date,current_flag)。

基本上,资产就是带有标签的东西。它不包含有关类别,制造商或型号的信息。如果你这样做,你就会对你的数据进行非正规化。它包含Model的外键,即该信息。我认为模型和制造商只不过是自由形式的文本,但在某些情况下,您的要求可能会将其中一个或两个变成表格。

您可以将具有资产的人存储在资产表中,但您没有这样的历史记录(尽管可以使用资产历史记录或审计表来完成)。