[英]I am trying to a write an update query for a table based on the value of an attribute in another table.
thus far I have 到目前为止,我有
UPDATE dbo.Demographics
SET MAIL_MAG = 0
Inner Join dbo.Name
On Demographics.ID=dbo.Name.ID
Where dbo.Name STATUS = 'CON'
What I am unsure is if I have to have the inner join and if I am doing it correctly. 我不确定的是我是否必须具有内部联接,以及是否正确执行了联接。 I know that the attribute in both tables is ID. 我知道两个表中的属性都是ID。
Also do I have to use "dbo." 我还必须使用“ dbo”。
This is the syntax for updating a table with a JOIN
in SQL Server. 这是在SQL Server中使用JOIN
更新表的语法。
You also should use aliases for tables. 您还应该对表使用别名。 For the Demographics
table I have used d
, for the Name
table I have used n
. 对于Demographics
统计表,我使用了d
;对于Name
表,我使用了n
。
You do not need to use dbo
in your update statement. 您无需在更新语句中使用dbo
。
UPDATE d
SET d.MAIL_MAG = 0
FROM Demographics d
INNER JOIN Name n On n.ID = d.ID
WHERE
n.STATUS = 'CON'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.