简体   繁体   English

T-SQL…表示法

[英]T-SQL … Notation

When researching ways to optimise bulk updates to SQL Server, I have come across the following query which works correctly but I'm having difficulty understanding how the '...' notation works in the following c# code snippet: 在研究优化SQL Server批量更新的方法时,我遇到了以下查询,该查询可以正常运行,但是在理解以下c#代码段中“ ...”表示法的工作方式时遇到了困难:

command.CommandText = "CREATE TABLE #TmpTable(...)";
command.ExecuteNonQuery();

command.CommandText = "UPDATE T SET ... FROM " + tableName + " T INNER JOIN #TmpTable Temp ON ...; DROP TABLE #TmpTable;"
command.ExecuteNonQuery();

There was a bug in the code so that the destination table was being updated directly instead of writing to the temporary table first. 代码中存在一个错误,因此直接更新了目标表,而不是先写入临时表。 The referenced code was using the ellipsis (...) as a placeholder but for some reason my code failed to throw an exception where it should have done. 引用的代码使用省略号(...)作为占位符,但由于某种原因,我的代码未能在应有的位置抛出异常。 The corrected snippet should read as follows: 更正后的代码段应如下所示:

command.CommandText = "CREATE TABLE #TmpTable(Id int, x int)";
command.ExecuteNonQuery();

// Insert updated rows read from 'tableName' into #TmpTable

command.CommandText = "UPDATE T SET T.x = Temp.x FROM " + tableName + " T INNER JOIN #TmpTable Temp ON T.Id = Temp.Id; DROP TABLE #TmpTable;"
command.ExecuteNonQuery();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM