hiddentao / squel

:office: SQL query string builder for Javascript
https://hiddentao.github.io/squel
MIT License
1.57k stars 231 forks source link

SQL Server Update Fails with Trigger ? #375

Open mikeloxiao opened 5 years ago

mikeloxiao commented 5 years ago

If a table has a trigger in sql server, then execute update with OUTPUT will cause it to fail.

The error message is RequestError: The target table 'tablename' of the DML statement cannot have any enabled triggers if the statement contains an OUTPUT clause without INTO clause.

More information on this problem and the workaround here: https://github.com/sequelize/sequelize/issues/4807

https://stackoverflow.com/questions/13198476/cannot-use-update-with-output-clause-when-a-trigger-is-on-the-table

Does anyone have a solution?

darrensapalo commented 5 years ago

Back in 2016, user @mgrivera posted his workaround, which was to add the hasTrigger: true option in the model definition.

TableName = sequelize.define('TableName', { 
    <field definitions> 
}, { 
    tableName: 'TableName', 
    hasTrigger: true 
});

This workaround fixed it for me, allowing me to perform my INSERT queries. Does this work for you?

mikeloxiao commented 5 years ago

You mean sequelize.js?

Because squel.js don't have the hasTrigger: true option.

darrensapalo commented 5 years ago

Yes, that is what I meant. Apologies.