sql - 使用 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
... ...
解决方案
您不需要 SP 来完成此操作。
尝试通过暂时禁用 FK 约束ALTER TABLE Products NOCHECK CONSTRAINTS ALL
推荐阅读
- javascript - 在 React 中解析日期对象
- powershell - 如何在 UIAutomation 中访问 UIAPane 项
- sql-server - SQL Server 存储过程不在计划缓存或 Profiler 中
- vba - 微软字。如何将确切的字符串复制到另一个文档?
- algorithm - 为什么我们应该在 GP 求和公式中使用模乘逆?
- opencv - Kinect2 的对象检测 API“无法处理此数据类型”错误
- python - 如何解决“安装 steem-python 时出错”
- powershell - 如何为 CSV 文件中的每一行导入前两个值 | 电源外壳
- anaconda - 在 Anaconda 上安装 Miniconda?
- reactjs - 将组件和道具作为参数传递