Re: Insert Multiple Rows into a Table Without Using Select
- From: Hugo Kornelis <hugo@xxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 28 Sep 2005 21:13:33 +0200
On Wed, 28 Sep 2005 10:59:03 -0700, RitaG wrote:
>Hi.
>
>I want to insert 4 rows into a SQL table.
>Can I do this without using 4 Insert statements?
>
>This is my SQL statement:
> Insert Into MyTable Values (1,2)
> (3,4)
> (5,6)
> (7,8)
>but I'm getting a compile error.
>I tried using a comma after each row (except the last) but that didn't work.
Hi Rita,
The subject suggests that you don't want to use SELECT (why??); if
that's the case, you'll have to use 4 INSERT .. VALUES statements.
Here's how to do it in one INSERT .. SELECT, using UNION:
INSERT INTO MyTable (Column1, Column2)
SELECT 1, 2
UNION ALL
SELECT 3, 4
UNION ALL
SELECT 5, 6
UNION ALL
SELECT 7, 8
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)
.
- Prev by Date: Re: query on day's transactions
- Next by Date: Re: Insert Multiple Rows into a Table Without Using Select
- Previous by thread: Re: query on day's transactions
- Next by thread: Re: Insert Multiple Rows into a Table Without Using Select
- Index(es):
Relevant Pages
|
|