SQL代码更新表

发布于 2024-12-09 03:18:52 字数 421 浏览 1 评论 0原文

我有两个表:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

野味少女 2024-12-16 03:18:52

如果我正确理解你的问题,我认为你只需要在 WHERE 子句中添加另一个条件:

UPDATE Assets 
   SET status = 1
  FROM Assets, Master
 WHERE Assets.AssetNo = Master.AssetNo
   AND Assets.AssetNo = 111

If I understand your question correctly, I think you just need another condition in your WHERE clause:

UPDATE Assets 
   SET status = 1
  FROM Assets, Master
 WHERE Assets.AssetNo = Master.AssetNo
   AND Assets.AssetNo = 111
逆夏时光 2024-12-16 03:18:52

你使用什么sql引擎?像这样的东西适用于 sql server:

Update a
SET Status = 1
FROM Assets a
JOIN Master m on a.AssetNo = m.AssetNo
WHERE a.AssetNo  = 111

What sql engine are you using? Something like this would work for sql server:

Update a
SET Status = 1
FROM Assets a
JOIN Master m on a.AssetNo = m.AssetNo
WHERE a.AssetNo  = 111
几度春秋 2024-12-16 03:18:52
UPDATE Assets SET status = 1
FROM Assets a JOIN Master m ON a.AssetNo = m.AssetNo
WHERE a.AssetNo = 999
UPDATE Assets SET status = 1
FROM Assets a JOIN Master m ON a.AssetNo = m.AssetNo
WHERE a.AssetNo = 999
找回味觉 2024-12-16 03:18:52
UPDATE a
SET a.Status = 1
FROM Assets AS a
INNER JOIN Master AS m ON a.AssetNo = m.AssetNo
WHERE m.AssetNo = @value
UPDATE a
SET a.Status = 1
FROM Assets AS a
INNER JOIN Master AS m ON a.AssetNo = m.AssetNo
WHERE m.AssetNo = @value
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文