Subject | Re: Inserting Rows into DB |
---|---|
Author | Adam |
Post date | 2006-05-17T00:04:31Z |
--- In firebird-support@yahoogroups.com, "Richard Thomas"
<rthomas@...> wrote:
INSERT INTO [TABLENAME] ([SOMEFIELD1, SOMEFIELD2])
SELECT SOMEFIELD3, SOMEFIELD4 FROM [ANOTHER TABLE]
Which is similar to a copy-paste operation, but that requires the data
to be already in the database somewhere else. You could use external
tables then such a query to import them all quickly, but for 100
records, it is not worth it.
development environment, but it should be there somewhere. Basically,
because using different parameter values doesn't require any change to
the plan, it is more efficient than rebuilding the query from scratch
(and a LOT easier to read).
In Delphi, it would be.
qry.sql.text := 'insert into blah (ID) Values (:myid)';
for i := 1 to 100 do
begin
qry.ParamByName('myID').Value := i;
qry.ExecSQL;
end;
To put your performance worries in perspective, inserting 1000 rows
should be under 1 second (on reasonable hardware). There will be some
overhead depending on which interface is used (in this case ODBC), but
what I am saying is 100 is not much.
Adam
<rthomas@...> wrote:
>ready to
> Hi All:
> I have successfully created a Firebird Database, table and am now
> insert some test data. I've read about the INSERT FROM syntax.or get
> It appears that the examples insert one row at a time using the VALUES
> clause. In my program I will read from a CSV or Random Access file
> some data for several rows, perhaps 30 to 100 in some other way,then want
> to insert these new rows into the FB database table. Is there somesyntax
> to build multiple VALUES list entries and insert them with one executeThe statement I think you may be thinking of is
> statement I can research further?
INSERT INTO [TABLENAME] ([SOMEFIELD1, SOMEFIELD2])
SELECT SOMEFIELD3, SOMEFIELD4 FROM [ANOTHER TABLE]
Which is similar to a copy-paste operation, but that requires the data
to be already in the database somewhere else. You could use external
tables then such a query to import them all quickly, but for 100
records, it is not worth it.
> Or, do I have to loop through the logic to define the COLUMN VALUESfor each
> row and perform an EXECUTE for each row I want to insert?Parameters is what you are after. I do not know how this works in your
> I'm considering performance, of course.
development environment, but it should be there somewhere. Basically,
because using different parameter values doesn't require any change to
the plan, it is more efficient than rebuilding the query from scratch
(and a LOT easier to read).
In Delphi, it would be.
qry.sql.text := 'insert into blah (ID) Values (:myid)';
for i := 1 to 100 do
begin
qry.ParamByName('myID').Value := i;
qry.ExecSQL;
end;
To put your performance worries in perspective, inserting 1000 rows
should be under 1 second (on reasonable hardware). There will be some
overhead depending on which interface is used (in this case ODBC), but
what I am saying is 100 is not much.
Adam