December 9, 2008 at 12:27 pm
I'm trying to insert multiple rows using the T-SQL below. Is there a more efficient way to do this? I've read a couple posts on here about using the UNION ALL statement.
USE Test
GO
INSERT INTO Practice
VALUES ('John', 'Jones', '99980', '45', 'Payson', 'Arizona')
INSERT INTO Practice
VALUES ('Mary','Jones','99982','25','Payson','Arizona')
INSERT INTO Practice
VALUES ('Eric','Edwards','88232','32','San Diego','California')
December 9, 2008 at 12:51 pm
rshafer (12/9/2008)
I'm trying to insert multiple rows using the T-SQL below. Is there a more efficient way to do this? I've read a couple posts on here about using the UNION ALL statement.USE Test
GO
INSERT INTO Practice
VALUES ('John', 'Jones', '99980', '45', 'Payson', 'Arizona')
INSERT INTO Practice
VALUES ('Mary','Jones','99982','25','Payson','Arizona')
INSERT INTO Practice
VALUES ('Eric','Edwards','88232','32','San Diego','California')
Yes UNION ALL is the way about it. If you can use SQL2008 then row constructors with VALUES use a more compact syntax
* Noel
December 9, 2008 at 1:11 pm
Unfortunately I am stuck with 2005 for now. Can you please provide an example using the UNION ALL statement?
December 9, 2008 at 1:54 pm
USE Test
GO
INSERT INTO Practice
select 'John', 'Jones', '99980', '45', 'Payson', 'Arizona'
union all
select 'Mary','Jones','99982','25','Payson','Arizona'
union all
select 'Eric','Edwards','88232','32','San Diego','California'
Cheers,
K
December 10, 2008 at 6:36 am
k man (12/9/2008)
USE TestGO
INSERT INTO Practice
select 'John', 'Jones', '99980', '45', 'Payson', 'Arizona'
union all
select 'Mary','Jones','99982','25','Payson','Arizona'
union all
select 'Eric','Edwards','88232','32','San Diego','California'
Cheers,
K
Thank you! That worked great.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply