﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » StrataFrame Application Framework - V1 » Business Objects and Data Access (How do I?)  » Two SQL statements executed for each row added?</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Tue, 09 Jun 2026 08:25:48 GMT</lastBuildDate><ttl>20</ttl><item><title>Two SQL statements executed for each row added?</title><link>http://forum.strataframe.net/FindPost12941.aspx</link><description>I am debugging some performance issues in my app (DB2 datasource), I was surprised to find that:&lt;br&gt;
&lt;br&gt;
1) it is executing an insert command for each row instead of a single INSERT statement &lt;br&gt;
2) why the SELECT after each INSERT?&lt;br&gt;
&lt;br&gt;
Is this right, doesn't look right to me. This is a single SAVE() call against my BO after ADD()ing records in a looping structure.&lt;br&gt;
&lt;br&gt;
Thanks for taking a look... debug info below, a pair of these exists for each row added.&lt;br&gt;
&lt;br&gt;
Command #: 	171&lt;br&gt;
Timestamp: 	2007-12-07 16:14:23.606&lt;br&gt;
General Command Settings&lt;br&gt;
Command Type: 	Text&lt;br&gt;
Object Type: 	DDTek.DB2.DB2Command&lt;br&gt;
Connection String: 	XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&lt;br&gt;
Transaction: 	False&lt;br&gt;
Command Settings&lt;br&gt;
CommandText: 	INSERT INTO "SIGMA"."EDI_MILNDX" ("MIL_CODEID", "MIL_NAME", "MIL_NUM", "MIL_RV") VALUES (?, ?, ?, ?)&lt;br&gt;
Command Parameters&lt;br&gt;
P0: 	'SHWX' [DbType: String | Size: 4 | Direction: Input | SourceColumn: MIL_CODEID | SourceVersion: Current]&lt;br&gt;
P1: 	'Shaw Industries' [DbType: String | Size: 15 | Direction: Input | SourceColumn: MIL_NAME | SourceVersion: Current]&lt;br&gt;
P2: 	'0' [DbType: Decimal | Size: 0 | Direction: Input | SourceColumn: MIL_NUM | SourceVersion: Current]&lt;br&gt;
P3: 	'0' [DbType: Int32 | Size: 0 | Direction: Input | SourceColumn: MIL_RV | SourceVersion: Current]&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Command #: 	172&lt;br&gt;
Timestamp: 	2007-12-07 16:14:23.668&lt;br&gt;
General Command Settings&lt;br&gt;
Command Type: 	Text&lt;br&gt;
Object Type: 	DDTek.DB2.DB2Command&lt;br&gt;
Connection String: 	XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&lt;br&gt;
Transaction: 	False&lt;br&gt;
Command Settings&lt;br&gt;
CommandText: 	SELECT "MIL_PK", "MIL_RV" FROM "SIGMA"."EDI_MILNDX" WHERE MIL_PK = IDENTITY_VAL_LOCAL()&lt;br&gt;
Command Parameters&lt;br&gt;
N/A 	No parameters are defined</description><pubDate>Mon, 10 Dec 2007 09:39:54 GMT</pubDate><dc:creator>Keith Chisarik</dc:creator></item><item><title>RE: Two SQL statements executed for each row added?</title><link>http://forum.strataframe.net/FindPost12953.aspx</link><description>OK thanks Ben.</description><pubDate>Mon, 10 Dec 2007 09:39:54 GMT</pubDate><dc:creator>Keith Chisarik</dc:creator></item><item><title>RE: Two SQL statements executed for each row added?</title><link>http://forum.strataframe.net/FindPost12951.aspx</link><description>The SELECT after the INSERT is to retrieve the auto-assigned primary key and row version column values from the database.&amp;nbsp; It is inefficient to use 2 queries, but unfortunately, the DB2 adapter that I was using did not support executing more than one text command at within the same querry and I could not find documentation that said that it was supported (where you can put 2 queries back to back in SQL Server with a ";").&amp;nbsp; You can, however, use stored procedures for your INSERTs to accomplish the same thing... one query to insert the record rather than 2.&amp;nbsp; As for inserting more than one record at a time, we would not be able to retrieve the assigned primary keys for the records.</description><pubDate>Mon, 10 Dec 2007 08:58:43 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item><item><title>RE: Two SQL statements executed for each row added?</title><link>http://forum.strataframe.net/FindPost12943.aspx</link><description>Above link didn't copy correctly.&lt;br&gt;
&lt;br&gt;
[b]You can also insert multiple rows into a table using the VALUES clause. The following example inserts two rows into the PROJECT table. Values for the Project number (PROJNO) , Project name (PROJNAME), Department number (DEPTNO), and Responsible employee (RESPEMP) are given in the values list. The value for the Project start date (PRSTDATE) uses the current date. The rest of the columns in the table that are not listed in the column list are assigned their default value.&lt;br&gt;
&lt;br&gt;
INSERT INTO PROJECT (PROJNO, PROJNAME, DEPTNO, RESPEMP, PRSTDATE)&lt;br&gt;
   VALUES('HG0023', 'NEW NETWORK', 'E11', '200280', CURRENT DATE),&lt;br&gt;
         ('HG0024', 'NETWORK PGM', ''E11", '200310', CURRENT DATE)[/b]</description><pubDate>Fri, 07 Dec 2007 16:13:40 GMT</pubDate><dc:creator>Keith Chisarik</dc:creator></item><item><title>RE: Two SQL statements executed for each row added?</title><link>http://forum.strataframe.net/FindPost12942.aspx</link><description>Seems an INSERT for each row is the "recommended" way on SQL Server, though many are reporting improved performance with a single INSERT and UNION ALL, but I digress.&lt;BR&gt;&lt;BR&gt;A quick Google (and my DB2 resource agrees) says this is how to insert multiple records in DB2 for better performance.&lt;BR&gt;&lt;BR&gt;How might I accomplish this?&lt;BR&gt;&lt;BR&gt;&lt;A href="http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic=/sqlp/rbafyinsert.htm"&gt;http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic=/sqlp/rbafyinsert.htm&lt;/A&gt;</description><pubDate>Fri, 07 Dec 2007 16:12:05 GMT</pubDate><dc:creator>Keith Chisarik</dc:creator></item></channel></rss>