sql server 2005中的更新语句
考虑以下 Dig,假设所有三个表都有一个列 Is_Deleted,默认设置为 0...我想更新 Is_Deleted=1< Customers 表的 /strong> 字段,其中 CustId=2 仅当行包含 CustId=2 和 Is_Deleted=1 时> 在订单和OrderItems中 表格...我不想使用Cascade选项。任何建议
(来源:microsoft.com)
Consider the following Dig, Assume that all the three tables have a column Is_Deleted by default it is set to 0... I want to update Is_Deleted=1 field of Customers table where CustId=2 only when the rows containing CustId=2 and Is_Deleted=1 in Orders and OrderItems
Tables... I dont want to use Cascade option.. Any suggestion
(source: microsoft.com)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
最简单的方法是存在。我假设您想检查 Orders 和 OrderItems。这也意味着您只需过滤 CustID 一次。
Easiest way is EXISTS. I assume you want to check both Orders and OrderItems. This also means you only filter on CustID once.
好吧,听起来不错...
我们是仅在删除与该客户关联的所有订单和所有订单商品时设置删除标志,还是仅在删除至少 1 个商品时设置删除标志。
Ok sounds fine...
Do we only set the deleted flag when all the orders and all the order items associated with that customer are deleted, or only if at least 1 item is deleted.
您可以使用表上的触发器 - 客户
您可以获得有关触发器的详细信息:
触发您可以检查 Updated 列的值,根据它您可以更新不同表的数据。
You can make the use of Triggers on Table - Customers
You can get details about triggers :
With Trigger you can check the Value of Updated column and depending on it you can update the data of different tables.