简体   繁体   English

我正在尝试根据另一个表中的属性值编写一个表的更新查询。

[英]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.

相关问题 我正在尝试根据与另一个表的匹配来更新表,但出现多部分标识符错误 - I am trying to update a table based on matches to another table, getting a multi-part identifier error 如何根据SQL Server 2008中另一个表中的值编写更新触发器来更新当前表? - How can I write an update trigger to update the current table based on a value in another table in SQL Server 2008? 我正在尝试使用基于另一个表的信息更新表 - I'm trying to update a table with information based on another table 我需要根据同一张表中一列的值选择记录。 - I need to select records based on the value of a column in the same table. oracle sql-根据另一个属性值更新同一表 - oracle sql - update same table based on another attribute value 使用while循环迭代表行并更新另一个表中的值。 我如何通过加入来做到这一点? - Using a while loop to iterate over table rows and update a value in another table. How can I do this with a join? MYSQL根据另一个表中的值写入表 - MYSQL Write to a table based on a value in another table 从两个表中各选择一个记录。 通过将另一个值与新表匹配来更新一个值 - select one record each from two table. update the one value by matching the another one to a new table 根据Mysql中的另一个表值更新表 - Update a table based on another table value in Mysql 如何根据另一个表更新表值 - How to update table value based on another table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM