Learn Node JS
node js sql
- How to connect MySQL database using node js?If you don't install MySQL then you can install MySQL by npm install mysql. Example Create Connection You can write connection code in a single file and call in all pages where you need to interact with database. var mysql = require('mysql'); var con = mysql.createConnection({ host: "localhost", user: "your database username", password: "database password" }); con.connect(function(err) { if (err) throw err; console.log("Database Connected!"); });
- How to pass an array in insert query using node js?The array of records can easily be bulk inserted into the node.js. Before insertion, you have to convert it into an array of arrays. Example var mysql = require('node-mysql'); var conn = mysql.createConnection({ // your database connection }); var sql = "INSERT INTO Test (name, email) VALUES ?"; var values = [ ['best interview question', 'info@bestinterviewquestion.com'], ['Admin', 'admin@bestinterviewquestion.com'], ]; conn.query(sql, [values], function(err) { if (err) throw err; conn.end(); });
- Write an SQL query to fetch “FIRST_NAME” from Worker table using the alias name as .The required query is: Select FIRST_NAME AS WORKER_NAME from Worker;
- Write an SQL query to fetch “FIRST_NAME” from Worker table in upper case.The required query is: Select upper(FIRST_NAME) from Worker;
- Write an SQL query to print the first three characters of FIRST_NAME from Worker table.The required query is: Select substring(FIRST_NAME,1,3) from Worker;
- Write an SQL query to print the FIRST_NAME from Worker table after removing white spaces from the right side.The required query is: Select RTRIM(FIRST_NAME) from Worker;
- Write an SQL query to print the FIRST_NAME from Worker table after replacing ‘a’ with ‘A’.The required query is: Select REPLACE(FIRST_NAME,'a','A') from Worker;
- Write an SQL query to print all Worker details from the Worker table order by FIRST_NAME Ascending.The required query is: Select * from Worker order by FIRST_NAME asc;
- Write an SQL query to print details for Workers with the first name as “Vipul” and “Satish” from Worker table.The required query is: Select * from Worker where FIRST_NAME in ('Vipul','Satish');
- Write an SQL query to print details of workers excluding first names, “Vipul” and “Satish” from Worker table.The required query is: Select * from Worker where FIRST_NAME not in ('Vipul','Satish');
- Write an SQL query to print details of the Workers whose FIRST_NAME contains ‘a’.The required query is: Select * from Worker where FIRST_NAME like '%a%';
4iv>