Sql的update只有部分列生效

请问一下各位,有没试过,一个Update语句里面,一个列更新成功,一个列数据不变?

update TableName set A='A',B = 'B' where id = '100'

原始数据:
A B ID
a b 100

第一次执行:
A B ID
a B 100

第二次执行:
A B ID
A B 100

如果各位都说正常不会出现这个情况,我再详细说说其他情况

估计问题都出在拼凑语句赋值上或XML内容上,语句每次把操作写个日志,有问题时查看
比如:拼凑语句每两次执行时,在中间间隔时间读数据可能会存在楼主的情况

比如拼凑逻辑为,两个栏位分两次更新
再更新A列
再更新B列

你的数据库是?

以你的语句为一个隐性事务,只有两个选项 都成功或失败

could you pls share the operation log for us to check further more?
something like this below.

图片说明

 SQL> select * from TableName;

A                                        B                                                ID
---------------------------------------- ---------------------------------------- ----------
a                                        b                                               100

SQL> update TableName set A='A',B = 'B' where id = '100';

1行が更新されました。

SQL> select * from TableName;

A                                        B                                                ID
---------------------------------------- ---------------------------------------- ----------
A                                        B                                               100

SQL>

那我分享一下大概的程序设计:
1.读取XML文件
2.根据内容,拼凑出sql语句
string sql = " update " + TableName + " set A=@A,B =@B where " + ColumnName + " = '" + DocumentID + "'";

分析过程:
1.这个问题是偶发性的,所以我也无法直接通过程序的断点来追查sql语句有没有问题
2.找到对应的XML文件,检查内容确实是“A”“B”
3.使用程序再运行一次就正常了
4.我百思不得其解,如果是读取“B”值失败了,一般也会是空值或者NULL什么的,理论上也不会出现我遇到过的情况

It's difficult to consider that there is anything wrong with database.
Maybe something wrong with your program.

could you please try to output the result log of string "sql" after the statement at least twice for you to analyze.

string sql = " update " + TableName + " set A=@A,B =@B where " + ColumnName + " = '" + DocumentID + "'";