79
Node.js MySQL Insert Records
INSERT INTO statement is used to insert records in MySQL.
Example
Insert Single Record:
Insert records in “employees” table.
Create a js file named “insert” in DBexample folder and put the following data into it:
Now open command terminal and run the following command:
Check the inserted record by using SELECT query:
SELECT * FROM employees;
Insert Multiple Records
Create a js file named “insertall” in DBexample folder and put the following data into it:
Now open command terminal and run the following command:
Output:
Check the inserted record by using SELECT query:
SELECT * FROM employees;
The Result Object
When executing the insert() method, a result object is returned.The result object contains information about the insertion.
It is looked like this:
Next TopicNode.js MySQL Update Record