1

Web 应用程序是用带有 MSSQL 后端的经典 ASP 编写的。在此特定页面上,管理员可以选择 1 名或任何/所有员工来分配项目。我试图找出一种简单的方法来将分配给它的人员的员工 ID 存储在一个列中。

员工列表是从另一个表生成的,并且可以是动态的(解雇或雇用),因此我希望程序足够灵活,可以根据这些表更改进行更改。

基本上需要知道如何将多个人分配给以后可以在不同页面或从不同查询中调用的项目。

对不起,n00bish 的问题,但谢谢!

4

2 回答 2

11

不要在一列中存储多个 ID!使用现有表的主键和要存储的单个 ID 创建另一个表。然后,您可以在这个新表中插入多行,创建 1:m(一对多)关系。例如,让我们看一个订单表:

order:
    order_id
    order_date

我有一个产品表...

product:
    product_id
    product_name

现在,您可以继续在订单中添加一个列,让您在订单中列出产品,但这将是一种糟糕的形式。你想要的是类似..

order_item:
    order_item_id
    order_id
    product_id
    quantity
    unit_price

然后,您可以执行联接以获取特定订单的所有产品...

select
    product.*

from orders 

inner join order_item on order_item.order_id = order.order_id
inner join product on product.product_id = order_item.product_id

where orders.order_id = 5

这是一个示例 order_id 为 5,这将按该顺序获取所有产品。

于 2009-04-16T14:30:26.457 回答
3

You need to create another table that stores these values such as. So this new table would store one row for each ID, and then link back to the original record with the original records ID.

于 2009-04-16T14:31:38.560 回答