SQL, SQL Server, Tutorials, Oracle, PL/SQL, Interview Questions & Answers, Joins, Multiple Choice Questions, Quiz, Stored Procedures, Select, Insert, Update, Delete and other latest topics on SQL, SQL Server and Oracle.
Insert Multiple Values in Table
Insert Multiple Values in Table
How to insert multiple values in table using only one insert?
Usually what we do is
USE Your_DB
GO
INSERT INTO DummyTable (Col_1, Col_2)
VALUES ('First',1);
INSERT INTO DummyTable (Col_1, Col_2)
VALUES ('Second',2);
INSERT INTO DummyTable (Col_1, Col_2)
VALUES ('Third',3);
GO
Above the clause INSERT INTO is repeated many times. Another way is to use UNION ALL and INSERT INTO … SELECT… clauses.
USE Your_DB
GO
INSERT INTO DummyTable (Col_1, Col_2)
SELECT 'First' ,1
UNION ALL
SELECT 'Second' ,2
UNION ALL
SELECT 'Third' ,3
GO
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment