Ask a Question related to Coldfusion Database Access, Design and Development.
-
sweetyp2005 #1
insert multiple row
How do i insert multiple rows in database.
for example: I have 3 list:
list1: a1,a2,a3,a4
list2: b1,b2,b3,b4
list3: c1,c2,c3,c4
I want to insert a1,b1,c1 in 1st row. a2,b2,c2 in 2nd row,...
How do I write one sql insert statement to do that?
sweetyp2005 Guest
-
insert multiple row and table
I have table1 and table 2, one to many relationship. How do I save 3 rows in table 1 and one row in table 2 at the same time? -
Multiple DB Insert
I have an XML file that has roughly 55,000 records. I need to parse the contents of the file and store it in a database. The problem I'm having is... -
Multiple Insert or Looping Insert
I built an application on an Access DB that allows a dispatcher to log trucks in the field at their location as they call in. There are three... -
Insert Multiple INTO multiple table
Is there an extension available that can insert into multiple database tables and then retrieve the ID of the first insert? Andy -
multiple insert problem !
hi ! had to come right back... this time i'm trying to do a multiple insert. in my admin website i want to add users to a specific project. i... -
mxstu #2
Re: insert multiple row
sweetyp2005,
It depends on your database. As zoeski80 mentioned, mySql does allow multiple
row inserts in a single cfquery but the syntax is not standard across most
databases (ie. may not be portable). Access does not allow multiple row
inserts in a single cfquery. Some other databases like sql server, etc allow
multiple insert statements in the same query with each statement separated by a
semi-colon.
<cfquery ...>
INSERT INTO someTable (column1, column2, column3)
VALUES ('a1',b1', 'c1');
INSERT INTO someTable (column1, column2, column3)
VALUES ('a2',b2', 'c2');
... etc....
</cfquery>
Verify that all (3) lists contain the same number of elements and then cfloop
from 1 to the total number of elements in the lists. Within each cfloop grab
the list elements at the current loop index position.
<cfset list1 = "a1,a2,a3,a4">
<cfset list2 = "b1,b2,b3,b4">
<cfset list3 = "c1,c2,c3,c4">
<!--- single insert per cfquery method --->
<cfif listlen(list1) gt 0>
<!--- verify lists contain same number of elements --->
<cfif listLen(list1) eq listLen(list2) AND listLen(list2) eq listLen(list3)>
<cfloop from="1" to="#listLen(list1)#" index="j">
<cfquery name="addData" datasource="#yourDSN#">
INSERT INTO someTable (column1, column2, column3)
VALUES ('#listGetAt(list1, j)#', '#listGetAt(list2, j)#', '#listGetAt(list3,
j)#')
</cfquery>
</cfloop>
<cfelse>
Oops! The list sizes don't match.
</cfif>
</cfif>
mxstu Guest
-
SQLMenace #3
Re: insert multiple row
INSERT INTO someTable
select 'a1',a2', 'a3','a4'
union all
select 'b1',b2', 'b3','b4'
union all
select 'c1',c2', 'c3','c4'
SQLMenace Guest



Reply With Quote

