我试图找出是否有办法更新记录,而不必列出要更新的每个列名称。
例如,如果我可以使用类似的东西,那将是很好的:
// the parts inside braces are what I am trying to figure out
UPDATE Employee
SET {all columns, without listing each of them}
WITH {this record with id of '111' from other table}
WHERE employee_id = '100'
如果可以这样做,那么编写此类查询的最直接/最有效的方法是什么?
这是不可能的,但..
你能行的:
begin tran
delete from table where CONDITION
insert into table select * from EqualDesingTabletoTable where CONDITION
commit tran
小心身份字段。
如何使用Merge?
https://technet.microsoft.com/en-us/library/bb522522(v=sql.105).aspx
它使您能够运行插入,更新和删除。另一条建议是,如果您要使用索引更新大型数据集,并且源子集小于目标但两个表都非常大,请先将更改移动到临时表。我试图合并两个表,每个表近200万行,20个记录需要22分钟。一旦我将增量移动到临时表,就需要几秒钟。
你可以通过删除表中的列并重新添加列并添加默认值来实现它。然后保存这将需要重建表