如何阻止Knex Query Builder对SQL Server的update()追加select @@rowcount?
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

