User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MS SQL section within the Web Development category of DaniWeb, a massive community of 426,405 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,370 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MS SQL advertiser: Programming Forums

insert multiple rows in database

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

Re: insert multiple rows in database

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

INSERT INTO test_table
SELECT 62
UNION
SELECT 91
UNION
SELECT 95
UNION 
SELECT 98
UNION 
SELECT 99

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

CREATE TABLE test
(
	val1 VARCHAR(10), 
	val2 VARCHAR(10), 
	val3 VARCHAR(10), 
	val4 VARCHAR(10)
)
GO

INSERT INTO test
(val1, val2, val3, val4)
(SELECT 'a1', 'a2', 'a3', 'a4')
UNION
(SELECT 'b1', 'b2', 'b3', 'b4')
UNION
(SELECT 'c1', 'c2', 'c3', 'c4')
GO
Reply With Quote  
All times are GMT -4. The time now is 1:34 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC