Slip 16 - B) Create a Node,js file that Select all records from the "Employee" table, and Update the salary of the given Eno.

Solution:


var mysql = require('mysql');


var con = mysql.createConnection({

  host: "localhost",

  user: "root",

  password: "",

  database: "employee_DB"

});


con.connect(function(err) {

  if (err) throw err;

  var sql = "UPDATE Employee SET Sal = 50000 WHERE Eno = 1";

  con.query(sql, function (err, result,display) {

    if (err) throw err;

    console.log(result.affectedRows + " record updated");

  });


  con.query("SELECT * FROM employee", function (err, result, fields) {

    if (err) throw err;

    console.log(result);

  });

});

Post a Comment

0 Comments