Thursday, May 5, 2016

Interview Question - How to Insert Multiple Rows in a Single SQL Query

There are so many different databases most of uses SQL language for their programming. we can easily use code from one database to another database. Unfortunately the reality is very different, not all the scripts from one database works in another database. Today we will see very interesting question where the user asked a question about inserting multiple rows in a single SQL query.


Answer: Writing a code to insert multiple rows in a single SQL query is not a difficult task, but it is indeed a challenge to create a script which will work with multiple database.

Example : create a sample table with two columns in it. Once the table is created insert three different rows in a single SQL query.

CREATE TABLE SampleTable (ID INT, Col1 VARCHAR(100));
INSERT INTO SampleTable (ID, Col1)
VALUES (1, 'One'), (2, 'Two'), (3, 'Three');
SELECT *
FROM SampleTable;
DROP TABLE SampleTable;
run this query in multiple database.




No comments:

Post a Comment