Insrt two Table at once

9 views
Skip to first unread message

Wallace Henrique

unread,
Aug 9, 2010, 3:06:39 PM8/9/10
to SQL Anywhere Web Development
hello
would like to know how to make an insert into two tables at once?

thanks.

Eric Farrar

unread,
Aug 13, 2010, 2:47:25 PM8/13/10
to SQL Anywhere Web Development
Hello Wallace,

It depends on what you mean by "at once". There is no way to make an
insert into multiple tables in the same statement. Each statement can
only insert into a single table. To insert into two tables, you would
need two separate statements such as:

INSERT INTO TABLE_A VALUES (...);
INSERT INTO TABLE_B VALUES (...);

Although you cannot insert into two tables in the same statement, you
can make the inserts happen at the same time. In other words, you can
make it so that either both inserts succeed, or both inserts fail. To
do this you use database transactions (http://en.wikipedia.org/wiki/
Database_transaction).

You can start a transaction using the BEGIN statement, and end the
transaction either using COMMIT (which means save everything you did),
or ROLLBACK (which means undo everything you did). So to insert rows
into two tables "at once", you would use:

BEGIN -- Starts the transaction
INSERT INTO TABLE_A VALUES (...);
INSERT INTO TABLE_B VALUES (...);
COMMIT -- Save the transaction

Hope this helps :)

- Eric




On Aug 9, 3:06 pm, Wallace Henrique <wallacehenrique.si...@gmail.com>
wrote:

Wallace Henrique Silva

unread,
Aug 14, 2010, 7:47:29 AM8/14/10
to sql-anywhere-w...@googlegroups.com
Thanks, more my problem is I have two tables CUSTOMERS and CLI_ENDERECOS, when I insert 
on clients he repeats the client code in the table with it can not CLI_ENDERECOS 
to insert in another table CLI_ENDERECOS. I decided as follows in an insert 
CUSTOMERS table, after I select a table of customers in getting the latest code, and 
updated table of CLI_ENDERECOS the selected code, the problem is that it's a 
routine and how the application is Web is slow.

Att, Wallace Silva 
Brazil.

2010/8/13 Eric Farrar <ianywher...@gmail.com>
--
You received this message because you are subscribed to the Google Groups "SQL Anywhere Web Development" group.
To post to this group, send email to sql-anywhere-w...@googlegroups.com.
To unsubscribe from this group, send email to sql-anywhere-web-dev...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sql-anywhere-web-development?hl=en.




--
Att, 

Wallace Silva

Eric Farrar

unread,
Aug 18, 2010, 12:46:35 PM8/18/10
to SQL Anywhere Web Development
Wallace,

Can you print the code that you are currently using?

Thanks,

- Eric

On Aug 14, 7:47 am, Wallace Henrique Silva
<wallacehenrique.si...@gmail.com> wrote:
> Thanks, more my problem is I have two tables CUSTOMERS and CLI_ENDERECOS,
> when I insert
> on clients he repeats the client code in the table with it can not
> CLI_ENDERECOS
> to insert in another table CLI_ENDERECOS. I decided as follows in an insert
> CUSTOMERS table, after I select a table of customers in getting the latest
> code, and
> updated table of CLI_ENDERECOS the selected code, the problem is that it's
> a
> routine and how the application is Web is slow.
>
> Att, Wallace Silva
> Brazil.
>
> 2010/8/13 Eric Farrar <ianywhere.efar...@gmail.com>
> > sql-anywhere-web-dev...@googlegroups.com<sql-anywhere-web- development%2Bunsu...@googlegroups.com>
> > .

Wallace Henrique Silva

unread,
Aug 20, 2010, 7:44:43 AM8/20/10
to sql-anywhere-w...@googlegroups.com
yes.

2010/8/18 Eric Farrar <ianywher...@gmail.com>
To unsubscribe from this group, send email to sql-anywhere-web-dev...@googlegroups.com.



--
Att, 

Wallace Silva

Reply all
Reply to author
Forward
0 new messages