将外键添加到列

时间:2013-06-10 15:23:36

标签: sql-server sql-server-2008

我有很多表,例如EmployeeType,OrderType,AddressType ......等等。这些表只有Id和Name,它们看起来一样,所以我决定只使用1个表来简化模式,你有表格: / p>

Type
------------
Id         int Identity
EntityId   id that represent the table check the table below
TypeId     id of each table, EmployeeType, OrderType, etc.
Name       Name of the type


Entity
------------
EntityId   
Name

这里有一些例子:

实体表:

EntityId   Name
1          EmployeeType
2          OrderType  

输入表格:

Id    EntityId  TypeId     Name
1     1         1          Employee
2     1         2          Manager

现在我有了Employee表,这个表有一个TypeId,当我的EntityId等于1(EmployeeType)时,我需要能够将FK放到Type表中吗?

0 个答案:

没有答案
相关问题