Insert same record on two different tables (no master detail)

Hi all,
I'd like to know how to insert 1 record into two different
tables.
the first table is corni_dati the second is cornidati_prev
anytime someone inserts a new record both tables should be
filled.
if ((isset($HTTP_POST_VARS["MM_insert"])) &&
($HTTP_POST_VARS["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO corni_dati (corni_id,
disciplina,
codice_modulo, insegnanti, classi, obiettivi, prerequisiti,
ud1, ud2,
ud3, ud4, ud5, ud6, metodologia, collegamenti, verifiche,
verifiche_note, durata, periodo_inizio, periodo_fine, note,
indirizzo,
modnum, modulo_titolo, `data`, compilato, descrizione) VALUES
(%s, %s,
%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s,
%s, %s, %s,
%s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($HTTP_POST_VARS['corni_id'],
"int"),
GetSQLValueString($HTTP_POST_VARS['disciplina'],
"text"),
GetSQLValueString($HTTP_POST_VARS['codice_modulo'], "text"),
GetSQLValueString($HTTP_POST_VARS['insegnanti'],
"text"),
GetSQLValueString($HTTP_POST_VARS['classi'],
"text"),
GetSQLValueString($HTTP_POST_VARS['obiettivi'],
"text"),
GetSQLValueString($HTTP_POST_VARS['prerequisiti'], "text"),
GetSQLValueString($HTTP_POST_VARS['ud1'],
"text"),
GetSQLValueString($HTTP_POST_VARS['ud2'],
"text"),
GetSQLValueString($HTTP_POST_VARS['ud3'],
"text"),
GetSQLValueString($HTTP_POST_VARS['ud4'],
"text"),
GetSQLValueString($HTTP_POST_VARS['ud5'],
"text"),
GetSQLValueString($HTTP_POST_VARS['ud6'],
"text"),
GetSQLValueString($HTTP_POST_VARS['metodologia'], "text"),
GetSQLValueString($HTTP_POST_VARS['collegamenti'], "text"),
GetSQLValueString($HTTP_POST_VARS['verifiche'],
"text"),
GetSQLValueString($HTTP_POST_VARS['verifiche_note'], "text"),
GetSQLValueString($HTTP_POST_VARS['durata'],
"int"),
GetSQLValueString($HTTP_POST_VARS['periodo_inizio'], "text"),
GetSQLValueString($HTTP_POST_VARS['periodo_fine'], "text"),
GetSQLValueString($HTTP_POST_VARS['note'],
"text"),
GetSQLValueString($HTTP_POST_VARS['indirizzo'],
"text"),
GetSQLValueString($HTTP_POST_VARS['modnum'],
"text"),
GetSQLValueString($HTTP_POST_VARS['modulo_titolo'], "text"),
GetSQLValueString($HTTP_POST_VARS['data'],
"date"),
GetSQLValueString($HTTP_POST_VARS['compilato'],
"text"),
GetSQLValueString($HTTP_POST_VARS['descrizione'], "text"));
mysql_select_db($database_itiscorni, $itiscorni);
$Result1 = mysql_query($insertSQL, $itiscorni) or
die(mysql_error());
$insertGoTo = "creacodice_doc.php";
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
header(sprintf("Location: %s", $insertGoTo));

If you are doing this then you really should have a look at
your database
design. Read up on the first 3 normal forms.
Pat.
"darrel" <[email protected]> wrote in message
news:ee77jg$302$[email protected]..
>
>
> --
>> Hi all,
>> I'd like to know how to insert 1 record into two
different tables.
>
> In your SQL query, just use two inserts:
>
> INSERT into TABLE1...; INSERT into TABLE2...
>
> Darrel
>

Similar Messages

  • How to handle an update of the same record from two different user JSP

    how do you handle an update of the same record from two different users in JSP... if one person updates the record from one drop downs should be updated as well.. is the possible.

    I'm not sure whether I understand your question. If one user changes a record then you would like other users to see those changes. Normally those changes will be visible to other users when they refresh their browser, after the first user has committed changes to the record. I you want to be sure that the same row isn't updated at the same time by to different user, you need to configure some locking (pessimistic locking) - this depends of what technology you use. In EJB3 pessimistic locking is performed by adding a version to every entity object. If you are using ADF, the framework is able to handle either pessimistic or even optimistic locking.
    If you want the changed row to be updated in other users browsers without any user interaction by these users, you should take a look at Reverse Ajax (ex. DWR http://ajaxian.com/archives/reverse-ajax-with-dwr) - or Ajax in general. But you will never get a realtime solution, where changes is visible in other users browsers right after each record update.

  • How to handle an update of the same record from two different user  in JSP

    how to handle an update of the same record from two different user
    how do you handle an update of the same record from two different users in JSP... if one person updates the record from one drop downs should be updated as well.. is the possible.

    Usually, if two users try to update the same row at the same time, you want the first to commit to succeed, and when the second commits, they should fail with the error that the row was being concurrently updated. They you may want to show them the new row values and give them the opportunity to merge their values with the new row values...
    How can you achieve this? Google optimistic locking.

  • Extracting unique records from two different tables record

    Hello,
    In the following code of two different tables www.testing.com exists in both tables. I want to compare two different columns of the two different tables to get unique records.
    SQL> select unique(videoLinks) from saVideos where sa_id=21;
    VIDEOLINKS
    www.testing.com
    SQL> ed
    Wrote file afiedt.buf
      1* select unique(picLinks) from saImages where sa_id=21
    SQL> /
    PICLINKS
    test
    test14
    www.hello.com
    www.testing.comThanks & best regards

    Unfortunatly you didn't mention the expected output. I guess it would be the one line
    "www.testing.com"
    in that case simply join the two tables.
    select *
    from saVideos v
    join saImages i on i.sa_id = v.sa_id and i.picLinks = v.videoLinks
    where v.sa_id=21;If needed then you could change the select list to retrieve only distinct values.
    select unique v.sa_id, v.videolinks
    from saVideos v
    join saImages i on i.sa_id = v.sa_id and i.picLinks = v.videoLinks
    where v.sa_id=21;I usually avoid distinct/unique whereever possible. This requires the database to do a sort and makes the query slow.
    Edited by: Sven W. on Feb 10, 2011 1:55 PM

  • Sum of same fields in two different tables

    Hi ,
    I am facing a problem, hope anyone would help
    I have two tables.. here is the sample data..
    create table t1
    (item_ID NUMBER(2),
    book_ID NUMBER(2),
    price NUMBER(2))
    insert into t1 (item_ID, book_ID, price) values (1,1,60);
    insert into t1 (item_ID, book_ID, price) values (1,2,70);
    insert into t1 (item_ID, book_ID, price) values (1,3,80);
    insert into t1 (item_ID, book_ID, price) values (2,1,10);
    insert into t1 (item_ID, book_ID, price) values (2,1,20);
    insert into t1 (item_ID, book_ID, price) values (1,3,40);
    create table t2
    (item_ID NUMBER(2),
    book_ID NUMBER(2),
    price NUMBER(2))
    insert into t2 (item_ID, book_ID, price) values (1,1,89);
    insert into t2 (item_ID, book_ID, price) values (1,2,29);
    insert into t2 (item_ID, book_ID, price) values (1,3,99);
    insert into t2 (item_ID, book_ID, price) values (2,1,55);
    insert into t2 (item_ID, book_ID, price) values (2,1,90);
    insert into t2 (item_ID, book_ID, price) values (1,3,10);
    as you can see, both tables have the same column names with different data. what
    I require is that i need to calculate the SUM of price grouped by book_id from
    both the tables in a single SQL statement output.
    so my required output is this:
    BOOK_ID SUM(PRICE)
    1 323
    2 99
    3 229
    where the SUM(price) for each book_id is for all the books in both the tables
    where book_id = 1 and then 2 in the second row and then 3 in the third row.
    Would anyone please help, as I am unable to write the query for this.?
    Thanks,
    Sonali.

    <quote>I was just curious if we can do that by some other SQl query and using UNION ALL operator...</quote>
    Of course there are other ways to do it ... but not necessarily better ... just to satisfy your curiosity:
    flip@FLOP> select book_id,sum(price) from t1 group by book_id;
       BOOK_ID SUM(PRICE)
             1    5898240
             2    4587520
             3    7864320
             4    2621440
    Elapsed: 00:00:01.02
    flip@FLOP> select book_id,sum(price) from t2 group by book_id;
       BOOK_ID SUM(PRICE)
             1   30670848
             2    3801088
             3   15597568
             5    1310720
    Elapsed: 00:00:02.06
    flip@FLOP> SELECT book_id, sum(price)
      2  FROM ( select * from t1
      3         union all
      4         select * from t2
      5       )
      6  GROUP BY book_id;
     
       BOOK_ID SUM(PRICE)
             1   36569088
             2    8388608
             3   23461888
             4    2621440
             5    1310720
     
    Elapsed: 00:00:04.01
    flip@FLOP>
    flip@FLOP> with a1 as
      2       (
      3         select book_id, sum(price) p
      4         from   t1
      5         group by book_id
      6       )
      7      ,a2 as
      8       (
      9         select book_id, sum(price) p
    10         from   t2
    11         group by book_id
    12       )
    13  select nvl(a1.book_id,a2.book_id), nvl(a1.p,0)+nvl(a2.p,0)  p
    14  from  a1 full outer join a2 on (a1.book_id = a2.book_id)
    15  ;
     
    NVL(A1.BOOK_ID,A2.BOOK_ID)          P
                             1   36569088
                             2    8388608
                             3   23461888
                             4    2621440
                             5    1310720
     
    Elapsed: 00:00:04.02

  • Hi friends, I have a doubt in inserting a field to database table and inserting the same values in two different tables

    I have a mpp screen for a cd library management system (we are practicing on it).
    We have a main screen where a user should enter the enteries and while clicking a add button it should be inserted in a table, Here the problem rises the table name are ztransaction and zstatus.The fields in mpp are cdid,customerid,transaction id,date of issue and duedate.Now after entering all the values on clicking add button it should be inserted to database table ztransaction and the field cdid alone should be inserted both in ztransaction and zstatus.
    Thank you

    Hi Raghuram R G,
    Check for Primary key and foreign key in the Database table??? Because of this it was not inserting...check and confirm??
    Regds,
    Vijay SR

  • Same dimension in two different fact tables

    Hi,
    I have one same dimension in two different fact tables. I would like to know how BI server choose the fact table when I do a request in this dimension.
    I know that is always using the same fact table, but I would like to know why choose this table and not the other.
    Thanks

    Sorry,
    But it doesn't seem to me.
    I reorded the tables in the BMM layer and it continues to use the same table, regardless this table is in last.
    After, I droped that table in the BMM layer and it continued to use the same.
    Thanks for your reply

  • How to create a foreign key for the table from two different tables?

    Hi All,
    I have a three table like below. In the below table SAMPLE_CONS_CHECK and SAMPLE_CONS2_CHECK will be having the primary key for NAME column. The same SAMPLE_CONS3_CHECK table also having the primary key for NAME column and forieign key for SAMPLE_CONS_CHECK and SAMPLE_CONS2_CHECK tables. See the below code 2
    code 1:
    CREATE TABLE SAMPLE_CONS_CHECK
            (NAME VARCHAR2(10),
            SERIES  VARCHAR2(5)
    CREATE TABLE SAMPLE_CONS2_CHECK
            (NAME  VARCHAR2(5),
             MODEL  NUMBER
    CREATE TABLE SAMPLE_CONS3_CHECK
            (NAME  VARCHAR2(5),
             MODEL_NO  NUMBER
            )code 2
    alter table SAMPLE_CONS_CHECK
    add constraint SAMPLE_CONS_CHECK_pk primary key (NAME)
    alter table SAMPLE_CONS2_CHECK
    add constraint SAMPLE_CONS2_CHECK_pk primary key (NAME)
    alter table SAMPLE_CONS3_CHECK
    add constraint SAMPLE_CONS3_CHECK_pk primary key (NAME)
    ALTER TABLE SAMPLE_CONS3_CHECK ADD
    CONSTRAINT SAMPLE_CONS3_CHECK_FK1 FOREIGN KEY
         NAME
    ) REFERENCES SAMPLE_CONS_CHECK
        NAME
    ) ON DELETE CASCADE;
    ALTER TABLE SAMPLE_CONS3_CHECK ADD
    CONSTRAINT SAMPLE_CONS3_CHECK_FK2 FOREIGN KEY
         NAME
    ) REFERENCES SAMPLE_CONS2_CHECK
        NAME
    ) ON DELETE CASCADE;From the above schenario i am able to insert the data to SAMPLE_CONS3_CHECK table. But the parent data is already available in the parent table. The problem is here two different constarints from two different tables. While inserting, it is checking from both the tables whether the parent is exist or not.
    How can i solve this problem? Can anyone halp me about this?
    Thanks
    Edited by: orasuriya on Aug 8, 2009 2:02 AM

    Actually the design is completely incorrect.
    What you say is
    I have
    'foo', 'foo series'
    'foo','foo model'
    'foo',666
    By virtue of table3 referring to both table1 and table2.
    This means you actually need to have 1 (one) table:
    'foo','foo series','foo model', 666
    And the 'problem' disappears.
    Sybrand Bakker
    Senior Oracle DBA

  • Will a sequence return same value for two different sessions?

    Is there a possibility that a sequence will return same value to two different sessions when it is referred exactly at the same instance of time?

    @Justin... Thanks for your insight; indeed, we too feel this shouldn't ever happen and never heard of it either, but there it is. (No, we haven't logged a TAR yet -- whatever that is -- partly because it didn't occur to us and partly because we only recently came across the issue and sensibly want to do some testing before we cry foul.)
    However, the code is pretty straight-forward, much like this (inside a FOR EACH ROW trigger body):
    SELECT <seqname>.NEXTVAL INTO <keyvar> FROM DUAL;
    INSERT INTO <tblname> (<keyfield>, <... some other fields>)
    VALUES(<keyvar>, <... some other values> );
    (where <tblname> is NOT the table on which the trigger is fired). This is the only place where the sequence is ever accessed. The sequence state is way below its limits (either MAXVALUE or <keyfield>/<keyvar> datatype size).
    In this setup, end users sometimes got an out-of-the-blue SQL error to the effect that uniqueness constraint has been violated -- as I said, we used to have a unique index on <keyfield> -- which leads us to assume that the sequence generated a duplicate key (only way for the constraint to be violated, AFAIK). We released the constraint and indeed, using a simple SELECT <keyfield>, COUNT(*) FROM <tblname> GROUP BY <keyfield> HAVING COUNT(*)>1 got us some results.
    Unfortunately, the <tblname> table gets regularly purged by a consumer process so it's hard to trace; now we created a logger trigger, on <tblname> this time, which tracks cases of duplicate <keyfield> inserts... We'll see how it goes.
    @Laurent... winks at the CYCLE thing Our sequence is (needless to say) declared as NOCYCLE and the datatype is large enough to hold MAXVALUE.

  • How can I combine post to two different tables with one form?

    I am trying to create a "phantom" record in a table to be used later in a report. How can I create a form and properly $_POST to two different tables? Thanks for any suggestions!

    In POST processing, just do the insert to one table, followed by the insert to the second table. I don't understand where you are getting stuck.
    Sometimes when we do an insert, we need the auto-generated ID from the newly created record as a "foreign key" for the record created in the second insert. MySQL has a nifty solution for that. The specific code depends on whether you are using the mysql, mysqli or PDO database connection.

  • Displaying same field with two different selection criteria.

    Post Author: spulkundwar
    CA Forum: Crystal Reports
    Hi All,  i want to display list of product in two different table having life counter field less than 0 and life counter field greater than 0. The product list is grouped by product category. The report should look like as shown belowProduct Category1                                             Soon expired (Life 0-25)                                                        Expired Products (Life < 0 )                            Product Name  Product Life                                                        Product Name    Product Life                                     Coke                            24                                                                        Pepsi                    -2                                    Beer                           12                                                                          Vodka            -34 Product Category2                                  Soon
    expired (Life 0-25)                                          Expired
    Products (Life < 0 )
                                Product Name  Product Life       
                                     Product Name   Product Life
                                 Pepsi                    14             
                                           Coke              -2  
                             Beer                     2                
                                          Vodka            -34
    Is this possible to show two tables in each report row? When i set selection formula to product name, it sets the same selection formula to all the fields in the report.

    Post Author: pvierheilig
    CA Forum: Crystal Reports
    Hello -
    Can't you set the group to be on the category?  Selecting the product name in the record selection formula will present only those product (as opposed to categories).
    A subreport, as suggested, will work as well, but your stated record selection will continue to produce the same results - check that, too.  Additionally, you could group on the category and add a group 'b' section (Section Expert; see the Help file).

  • How to display same screen with two different options!!

    Hi All,
    I have created a new entry form where user can enter a new record by selecting from combo select list or manua entry text fields. The same screen has to be used in two ways.
    New entry screen. and once user enetr data clik on sumbit it will insert into database.
    But when the user click on "View" button i need to display the same screen but with existing data insted of empty fields.
    How to achieve this in teh same screen, insated of creating duplicate screen.
    Thanks,
    Anoo..

    Hi,
    Try to use form on a report with report on page 1 and form on page 2.
    When the user clicks edit icons he will be directed to page to to see the values that are entered, make sure form is not updatable.
    If the user clicks create from page 1 then he will be directed to page 2 where he can enter data to insert new record.
    If you need in more detail, explain the scenario how you want, so that I can create an example for you.
    Thanks,
    Ramesh P.

  • Find if there is any common record in two internal tables

    hi,
    I have two internal tables of same structure... say A and B.
    I need to know if there are any common lines in them.
    one way is to loop in any one of them and keep executing a read on the other.
    can anyone suggest a better way.
    thanks,
    Arindam.

    Hi Arindam,
    To find common records in two internal tables, they can be compared
    If INT_DATA1 EQ INT_DATA2.
    endif.
    The first criterion for comparing internal tables is the number of lines they contain. If two internal tables contain the same number of lines, they are compared line by line, component by component.
    If the internal tables contain the same number of records and are sorted on the same key, the comparison stops at the line where the records are not common. For example, if the number of common records is 4, the comparison stops at the 5th line and sy-tabix becomes 5.
    Hope it helps.
    Regards,
    Nupur

  • Update two different tables by a single sql query:

    Hi All,
    i need to update two different talbes in a single sql query..
    i m using the following query
    UPDATE FT_User_Alert SET Subscription = 'W' where product_key=1 and measure_key = 12
    AND
    UPDATE LU_Monthly_Alert_Budget_Sheet SET Min_Red_Range ='16.0' AND Max_Green_Range ='24.0'AND Max_Red_Range ='27.0'AND Min_Green_Range ='16.0' where product_key='1' and measure_key = 12
    i m getting the following error:
    Odbc driver returned an error (SQLExecDirectW).
    Error Details
    Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 43093] An error occurred while processing the EXECUTE PHYSICAL statement. [nQSError: 17001] Oracle Error code: 936, message: ORA-00936: missing expression at OCI call OCIStmtExecute: UPDATE FT_User_Alert SET Subscription = 'W' where product_key=1 and measure_key = 12 AND UPDATE LU_Monthly_Alert_Budget_Sheet SET Min_Red_Range ='16.0' AND Max_Green_Range ='24.0'AND Max_Red_Range ='27.0'AND Min_Green_Range ='16.0' where product_key='1' and measure_key = 12 . [nQSError: 17011] SQL statement execution failed. (HY000)
    SQL Issued: EXECUTE PHYSICAL CONNECTION POOL writeback UPDATE FT_User_Alert SET Subscription = 'W' where product_key=1 and measure_key = 12 AND UPDATE LU_Monthly_Alert_Budget_Sheet SET Min_Red_Range ='16.0' AND Max_Green_Range ='24.0'AND Max_Red_Range ='27.0'AND Min_Green_Range ='16.0' where product_key='1' and measure_key = 12
    but when i m ushin the same query in Microsoft SQL Server it executes properly:
    please help me out...

    Duplicate thread. I've already answered on your other thread...
    update two different tables by a single sql query:

  • Sum two different columns from two different tables

    Can you select and sum two different columns, from two different tables in the same sql statement?
    i.e.
    table1
    Item----OnHand_Qty
    A--------10
    A--------15
    B--------10
    B--------10
    C--------20
    table2
    Item----Trx_Qty
    A--------2
    A--------4
    A--------6
    B--------1
    B--------1
    C--------4
    I'm looking for the following results from a query
    Item----Sum(Onhand_Qty)---Sum(Trx_Qty)
    A--------25

    Like this?
    SQL> create table table1 (item,onhand_qty)
      2  as
      3  select 'A', 10 from dual union all
      4  select 'A', 15 from dual union all
      5  select 'B', 10 from dual union all
      6  select 'B', 10 from dual union all
      7  select 'C', 20 from dual union all
      8  select 'D', 30 from dual
      9  /
    Tabel is aangemaakt.
    SQL> create table table2 (item, trx_qty)
      2  as
      3  select 'A', 2 from dual union all
      4  select 'A', 4 from dual union all
      5  select 'A', 6 from dual union all
      6  select 'B', 1 from dual union all
      7  select 'B', 1 from dual union all
      8  select 'C', 4 from dual union all
      9  select 'E', 3 from dual
    10  /
    Tabel is aangemaakt.
    SQL> select nvl(t1.item,t2.item) item
      2       , t1.sum_onhand_qty
      3       , t2.sum_trx_qty
      4    from ( select item, sum(onhand_qty) sum_onhand_qty
      5             from table1
      6            group by item
      7         ) t1
      8         full outer join
      9         ( select item, sum(trx_qty) sum_trx_qty
    10             from table2
    11            group by item
    12         ) t2
    13         on (t1.item = t2.item)
    14  /
    I SUM_ONHAND_QTY SUM_TRX_QTY
    A             25          12
    B             20           2
    C             20           4
    E                          3
    D             30
    5 rijen zijn geselecteerd.Regards,
    Rob.

Maybe you are looking for

  • SAP Business One 8.8 - Reviews & Videos

    The Orchestra Team has a centralized place for previews and reviews of SAP Business One 8.8 If your customers or prospects are interested in getting an honest "first impression", this is a great start. [Your Resource for Information About SAP Busines

  • Weak Xcelsius when consuming web services

    Post Author: cybercowboy CA Forum: Xcelsius and Live Office The following wsdl is deployed on weblogic 10.0. SoapUI, java, .net, flex ... can all consume it. Only Xcelsius can not even load the wsdl. Anybody who is familiar with the Xcelsius can give

  • How do I set Firefox to automatically view text files in my browser window? Sometimes FF insists on downloading them instead.

    I use my browser to monitor real time data streams (oceanography) and want to be able to view processing log files directly in my browser window. I have symbolic links from these logs (*.log) to my web server's document directory, using .txt as a fil

  • Duplicate Workitem in Inbox

    Hi Gurus, I have created new Z event for Service notification (ZCHANGE) which will trigger on the change of service notification. I have configured this using TCODE SWEC. While configuring this I have selected option 'On Change'. For creation of Serv

  • Do hyperlinks stay?

    Hi - our biggest robo project is our planning scheme, with over 1500 pages in multiple Word docs which are all linked together with cross referencing hyperlinks - about 4,000 of them. When we imported it in a previous version of roboinfo, the links w