You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何阻止Knex Query Builder对SQL Server的update()追加select @@rowcount?

How to Prevent Knex from Appending select @@rowcount to Update Queries for SQL Server

Hey there, I’ve run into this exact behavior with Knex and SQL Server before—here’s how you can fix it:

Knex automatically adds select @@rowcount to update statements for SQL Server by default because it tries to return the number of affected rows. To disable this, you just need to add the .options({ noRowcount: true }) method to your query chain.

Modified Code

let updateQuery = knex('details')
  .where('id', studentId)
  .andWhere({name: Name})
  .update({ 'value': Value, 'updated_at': new Date() })
  .options({ noRowcount: true });

Why This Works

The noRowcount option tells Knex not to append the select @@rowcount clause. This is specific to SQL Server’s query builder implementation in Knex, since other databases handle returning affected rows differently.

If you ever do need to get the number of affected rows later, you can simply remove this option and Knex will go back to including the rowcount query.

内容的提问来源于stack exchange,提问作者Puranik K

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 21:32:28