UPDATE(简化的问题,从问题中删除了 C#)
在以下情况下,如何编写一个可以识别两行相同的 UPSERT...
看看怎么有一个\b [退格键]在那里编码(奇怪的小字符)? SQL 将它们视为相同。虽然我的 UPSERT 将此视为new data并在应该有更新的地方尝试插入。
//UPSERT
INSERT INTO [table]
SELECT [col1] = @col1, [col2] = @col2, [col3] = @col3, [col4] = @col4
FROM [table]
WHERE NOT EXISTS
-- race condition risk here?
( SELECT 1 FROM [table]
WHERE
[col1] = @col1
AND [col2] = @col2
AND [col3] = @col3)
UPDATE [table]
SET [col4] = @col4
WHERE
[col1] = @col1
AND [col2] = @col2
AND [col3] = @col3
您需要 @ 符号,否则会遇到 C# 字符转义序列。
C# 定义了以下字符转义序列:
\' - single quote, needed for character literals
\" - double quote, needed for string literals
\\ - backslash
\0 - Unicode character 0
\a - Alert (character 7)
\b - Backspace (character 8)
\f - Form feed (character 12)
\n - New line (character 10)
\r - Carriage return (character 13)
\t - Horizontal tab (character 9)
\v - Vertical quote (character 11)
\uxxxx - Unicode escape sequence for character with hex value xxxx
\xn[n][n][n] - Unicode escape sequence for character with hex value nnnn (variable length version of \uxxxx)
\Uxxxxxxxx - Unicode escape sequence for character with hex value xxxxxxxx (for generating surrogates)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)