Insert two tables with a single query (same ID)

Hello

I want to insert two tables at the same time (with a single request) provided that both records get inserted with the same identifier. How can I do this?
Table Movies
id 
name

Table Category
movie_id
cat_type
(a) insert in the first table, retrieve the id (can be using
my_sequence.currval
and then insert into another table.

question: He brings three queries to the Database, I also suspect that when several people trying to insert there is a problem, I could be wrong.

I have no other idea.

Greatly appreciated!

think you need to do as an anonymous pl/sql block.

Dim cn As New OracleConnection("DataSource = xx'; user id = xx; password = xx;")

Try
 'build the anonymous pl/sql
 Dim sb as New System.Text.StringBuilder
 sb.Append("declare")
 sb.Append(" l_N number;")
 sb.Append("begin")
 sb.Append("insert into movies (id,name) values (my_sequence.nextval, 'film1') returning id  into l_N;")
 sb.Append( "insert into category values (l_N, 'Category type');")
 sb.Append(" END;")

 'create commd object

 Dim cmd as New OracleCommand(sb.ToString,cn)
 cmd.Connection.Open()
 cmd.ExecuteNonQuerry()
 cmd.Connection.Close()
 cmd.dispose()
 Catch ex as Exception

  blah blah blah

End try

  

Published by: pollywog on May 28, 2010 10:48

Published by: pollywog on May 28, 2010 10:49

Tags: Database

Similar Questions

  • I try to insert two images in a single document, group them, and then export it to a jpg file but cannot do so can you please help. Thank you

    I try to insert two images in a single document, group them, and then export it to a jpg file but cannot do

    Hello sara,.

    For my part, I prefer to use my German PS in this way (I try to translate the commands):

    Use the same height for both images.

    Open the first image in PS.

    Use Bild > Arbeitsflache (Image > work plan?) See screenshot:

    From there:

    Give him the new with, by clicking on the left or the right indicating the hand playing around (trial and error).

    Now you can insert your second image.

    Hans-Günter

  • Insert two tables simultaneously

    I want to insert records into two or several other table with a single statement. Is this possible in Oracle XE?

    How can I combine the following in a single statement?
    insert into addressbook(name) values('test');
    insert into email(email) values('[email protected]');
    Thank you and best regards

    Hello

    It is possible to merge several inserts with 'all' BLOCinstruction, check

    INSERT ALL
    INTO addressbook(name)
    VALUES('test')
    INTO email(email)
    VALUES('[email protected]')
    SELECT * FROM dual
    

    General synthax so is;

    INSERT ALL
    INTO  VALUES ()
    INTO  VALUES ()
    ...