View Single Post
Join Date: Jun 2007
Posts: 1
Reputation: JacobSteelsmith is an unknown quantity at this point 
Solved Threads: 0
JacobSteelsmith JacobSteelsmith is offline Offline
Newbie Poster

Re: insert multiple rows in database

 
0
  #6
Jun 22nd, 2007
Just replying for anyone looking for an answer. Using MS SQL, you can do the following:

  1. INSERT INTO test_table
  2. SELECT 62
  3. UNION
  4. SELECT 91
  5. UNION
  6. SELECT 95
  7. UNION
  8. SELECT 98
  9. UNION
  10. SELECT 99

This will insert 5 rows into the table. Testing this on SQL Server 2000, the following works:

  1. CREATE TABLE test
  2. (
  3. val1 VARCHAR(10),
  4. val2 VARCHAR(10),
  5. val3 VARCHAR(10),
  6. val4 VARCHAR(10)
  7. )
  8. GO
  9.  
  10. INSERT INTO test
  11. (val1, val2, val3, val4)
  12. (SELECT 'a1', 'a2', 'a3', 'a4')
  13. UNION
  14. (SELECT 'b1', 'b2', 'b3', 'b4')
  15. UNION
  16. (SELECT 'c1', 'c2', 'c3', 'c4')
  17. GO
Reply With Quote