很难用一句话来描述。在数据库中,我有一个分为2个表的表,因为列大小超过了服务器的最大值。这两个表由唯一ID连接。第一个表中有一个标识行的guid。像这样:
Table_1
AGUID Join_Key Other columns ...
aabbcc 1 ...
ddeeff 2 ...
Table_2
Join_Key Field_To_Update Other different columns ...
1 ...
2 ...
我在Field_To_Update中有GUID和字符串。
update table_2 set Field_To_Update = 'the new column value'
where
table_2.Join_Key = table_1.Join_Key and
table_1.AGUID = 'aabbcc'
这是正确的做法吗?
在真实数据库中,表名非常长 - 可以使用别名吗?
答案 0 :(得分:1)
关闭,但您需要from
子句:
update t2
set Field_To_Update = 'the new column value'
from table_2 t2 join
table_1 t1
on t2.Join_Key = t1.Join_Key and
where t1.AGUID = 'aabbcc';
答案 1 :(得分:1)
您可以使用加入更新
Update a
SET a.Field_To_Update = 'the new column'
from table_2 a
JOIN Table_1 b
on a.Join_key = b.Join_key
where b.AGUID = 'aabbcc'
答案 2 :(得分:1)
解决您的问题
update b set Field_To_Update = 'the new column value'
from table_1 as a
inner join table_2 as b on a.Join_Key = b.Join_Key
where
a.AGUID = 'aabbcc'
答案 3 :(得分:1)
Update t2
set Field_To_Update = 'column Name'
from table_2 t2
INNER JOIN table_1 t1 on t2.Join_Key = t1.Join_Key
where t1.AGUID = 'aabbcc';