Click here to Skip to main content
15,897,226 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how do i insert multiple rows values into table through one query

insert into tablename (col1,col2) values('abc','qwe');
insert into tablename (col1,col2) values('def','hkg');
Posted
Updated 3-Jul-11 23:25pm
v2
Comments
PSK_ 4-Jul-11 5:26am    
Are the values which you are trying to insert are coming from some other table?

 
Share this answer
 
Row constructor in SQL2008
INSERT INTO MyTable (FirstCol, SecondCol)
VALUES ('First',1),
('Second',2),
('Third',3),
('Fourth',4),
('Fifth',5)


Ref:http://blog.sqlauthority.com/2008/07/02/sql-server-2008-insert-multiple-records-using-one-insert-statement-use-of-row-constructor/[^]
 
Share this answer
 
Try:
INSERT INTO myTable ([name], [date]) VALUES ('Joe', 2011-04-02), ('Joe', 2011-04-03), ('Joe', 2011-04-04), ('Joe', 2011-04-05)
 
Share this answer
 
SQL
INSERT INTO myTable ([name], [date]) 
SELECT 'Aneesh','01/01/2010'
SELECT 'Ajith','01/01/2006'
 
Share this answer
 
v2
Comments
Christian Graus 4-Jul-11 6:06am    
Well, that's dumb. It's the same as Griff's, except that it's stupid. Why bother posting that ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900