Node.js MySQL删除记录

DELETE FROM命令用于从表中删除记录。

例子

从城市为德里的雇员表中删除雇员。

在DBexample文件夹中创建一个名为” delete”的js文件, 并将以下数据放入其中:

var mysql = require('mysql');
var con = mysql.createConnection({
host: "localhost", user: "root", password: "12345", database: "srcmini"
});
con.connect(function(err) {
if (err) throw err;
var sql = "DELETE FROM employees WHERE city = 'Delhi'";
con.query(sql, function (err, result) {
if (err) throw err;
console.log("Number of records deleted: " + result.affectedRows);
});
});

现在打开命令终端并运行以下命令:

Node delete.js
Node.js删除记录1

你可以使用SELECT语句验证已删除的记录:

Node.js删除记录2

来源:

https://www.srcmini02.com/27912.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_38369.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?