首页 > 解决方案 > 使用 SQL 存储过程同时更新多个观察值

问题描述

我正在尝试在 SQL 中同时更新多个表。我有一个包含 ProductName 和 ProductTypeID 的 Products 表。我还有另一个名为 ProductCategory 的表,其中包含 ProductTypeID 作为主键和完整的产品类型名称。例如,

Products Table
ProductName  ProductTypeID  Price ...
Bananas      FR             0.79  ...
Milk         DR             2.19  ...
...          ...            ...   ...

ProductCategory Table
ProductType  CategoryName
FR           Fruit
DR           Dairy
...          ...

在我的数据库中,水果和蔬菜部分是组合类别,所以我希望“水果”变成“农产品”,“FR”变成“公关”。但是,对于多表配置,我正在努力寻找一种方法来做到这一点。我一直在使用存储过程,因为这似乎是完成此任务的最简单方法。

结果如下所示:

Products Table
ProductName  ProductTypeID  Price ...
Bananas      PR             0.79  ...
Milk         DR             2.19  ...
...          ...            ...   ...

ProductCategory Table
ProductType  CategoryName
Produce      PR
DR           Dairy
...          ...

标签: sqlsql-servertsqlsql-update

解决方案



推荐阅读