2009-12-13 44 views
1

我正在设置资产跟踪数据库。黑莓,个人电脑,服务器,显示器,扬声器,键盘,鼠标,椅子,办公桌,立方体,立方体墙壁,打印机,冰箱,微波炉......各种各样的东西都有不同的资产。 这个范围将是我的分类表:资产数据库设计问题

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

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

我相信这将是一个不错的设计使用一个良好的数据库设计执行以下操作:如果模型的制造商被称为

    • 它不可能存储相同型号ID在与不同类别或制造商的数据库别处
  • 的资产存储在数据库中必须有一个分类
  • 使用一个ID为“未知”的任何3的说明会不舒服,但可能是必要的)

所以,当一个模型可能有知名厂家,资产可能有一个模型,或制造商或两者,它应该始终有一个类别。

下面是我想出的,到目前为止,我想过使用触发器来执行什么直接的外键不会

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 
) 

或者有未接船,有设计这个办法这是convienent(有modelid,manufacturerid和产品上的所有资产表直接而强制执行正确的独特类型?

+1

所有字段名称中的z是什么?不要那么做。 – Joe 2009-12-13 03:23:19

+0

这是我在工作中采用的一种做法,查找表是用z预先固定的。我将它带入查询表的ID字段 – Maslow 2009-12-13 04:19:12

回答

4

我就这样做了。

  • 资产(ID,男odel_id,asset_tag,created_date);
  • 模型(id,category_id,manufacturer,model,description);
  • 类别(id,name);
  • Person(id,title,given_names,surname,job_title,...);
  • 赋值(id,asset_id,person_id,start_date,end_date,current_flag)。

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

您可以将拥有该资产的人存储在资产表中,但您不会以这种方式获取历史记录(尽管这可以通过资产历史记录或审计表完成)。

+0

是的,历史将来自资产历史表 – Maslow 2009-12-13 01:52:30

+0

在模型表上有两个字段的想法:一个用于实际模型,如果它是已知的,另一个用于模糊描述if不知道它为我完成,谢谢。 – Maslow 2009-12-13 17:14:10