Call node.js function on insert in Sql Server -
i'm using sql server , have function in node.js want executed everytime new row inserted in specific table.
this code want run when change made in table.
private sql = require('mssql'); private currentid: any; `private config = { user: 'sa', password: 'sa', server: '192.168.100.2', port: '1433', database: 'test1', connectiontimeout: 100000,}; ` public checkdatabase() { this.sql.connect(this.config).then((connection: any) => { new this.sql.request(connection).query('select eventid events order eventid desc').then((recordset: any) => { console.log(recordset.recordset[0].eventid); if (this.currentid == recordset.recordset[0].eventid) { console.log("they same " + this.currentid + " " + recordset.recordset[0].eventid); } else { console.log("not same " + this.currentid + " " + recordset.recordset[0].eventid); } this.currentid = recordset.recordset[0].eventid; }); }); }
any suggestions please?
a general way create trigger insert operation - means given code be executed after every insert in given table:
create trigger name_of_your_trigger on test1.events after insert /* here should specify want do, instance print something: */ print "hello world" go
see docs more info: https://docs.microsoft.com/en-us/sql/t-sql/statements/create-trigger-transact-sql
Comments
Post a Comment