Slip 5 b
b. Create a N ode.js file that Select all records from the "customers" table, and delete the specified
record.
var mysql=require('mysql');
var cn=mysql.createConnection({
host:"localhost",
user:"root",
password:"",
database:"mydb"
});
cn.connect(function(err){
if(err) throw err;
console.log("connected!");
var sql="SELECT * from customer"
cn.query(sql,function(err,result){
if(err)throw err;
console.log(result);
});
var sql1 = "DELETE FROM customer WHERE caddress ='Pune'";
cn.query(sql1, function (err, result) {
if (err) throw err;
console.log("Number of records deleted: " + result.affectedRows);
});
})
/* Output*/
C:\Users\NEW\nodex>node custtable.js
connected!
[
RowDataPacket { cno: 1, cname: 'Ram', caddress: 'Pune' },
RowDataPacket { cno: 2, cname: 'Kshitij', caddress: 'Pimpri' }
]
Number of records deleted: 1
^C
C:\Users\NEW\nodex>node custtable.js
connected!
[ RowDataPacket { cno: 2, cname: 'Kshitij', caddress: 'Pimpri' } ]
Number of records deleted: 0
^C
No comments:
Post a Comment