SQL Server 的一个陷阱

今天发现一些数据有异常,开头的字符是Unicode 0xFEFF, 于是将其删除,于是执行下列语句:
UPDATE table SET data = RIGHT(data, LEN(data)-1) WHERE LEN(data)>0 AND data LIKE NCHAR(0xFEFE)+N’%’
结果很不幸啊,全部数据都被去掉了一个字符
于是,又用下列语句验证了一下:
SELECT COUNT() FROM table WHERE 1=1
SELECT COUNT(
) FROM table WHERE data LIKE NCHAR(0xFEFE)+N’%’
结果一样,就是说,全部数据都中选.

幸好事先保存了备份. 不然麻烦可真大.

Leave a Reply

Your email address will not be published. Required fields are marked *