SQL代码更新表
我有两个表:
Master Table Assets Table
-AssetNo- -AssetNo-
AssetNo
是 PK,它是链接两个表的外键。现在,我想更新使用:
UPDATE Assets
SET status = 1
FROM Assets, Master
WHERE Assets.AssetNo = Master.AssetNo
如果我使用此命令,具有相同 assetNo
的所有资产将自动更新为 1。
如何使用特定 assetNo
IE 进行编码: WHERE 111(来自资产)=111(来自主数据)
I have two tables:
Master Table Assets Table
-AssetNo- -AssetNo-
AssetNo
is the PK, and it's a foreign key to link the two tables. Now, I'd like to update using:
UPDATE Assets
SET status = 1
FROM Assets, Master
WHERE Assets.AssetNo = Master.AssetNo
If I use this command, all asset with the same assetno
will automatic update to 1.
How to code with specific assetNo
IE: WHERE 111(from Assets)=111(from Master)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果我正确理解你的问题,我认为你只需要在 WHERE 子句中添加另一个条件:
If I understand your question correctly, I think you just need another condition in your WHERE clause:
你使用什么sql引擎?像这样的东西适用于 sql server:
What sql engine are you using? Something like this would work for sql server: