Update,Insert,Delete on table T1 as per matching or non-matching rows in T2

Hi,
Need a solution for the following:
I have two tables T1 and T2:
T1
NAME LINK
a a1
a a2
b b1
c c1
c c3
d d1
T2
NAME LINK
a a1
a a3
b b1
b b2
c c1
c c2
c c3
Requirement: data in table T1 should be same as T2 for the matching values in column 'NAME'. So finally data in T1 should be:
T1
NAME LINK
a a1
a a3 -- (a,a3) added and (a,a2) deleted
b b1
b b2 --(b.b2) added
c c1
c c2 --(c,c2) added
c c3
d d1 --(d,d1) left as it is as value 'd' not found in T2
Any help writing a procedure would be appreciated.
Thanks,
Priyanka

delete t1
where name in (select name from t2);
insert into t1 (name, link)
select name, link from t2

Similar Messages

  • What's the exact trigger for when updating/inserting/deleting data from one DB to another DB which contains same info?

    Hi guys,
    I have created a copy of the AdventureWorks2012 DB called AdventureWorks2012_new on the same instance.
    I have created the following trigger below but my friend who is a DBA told me that this is not correct and I should be using the inserted table when creating this trigger. I would like AdventureWorks2012_new DB to be updating/inserting/deleting data from
    the same tables that have been updated/inserted/deleted in the AdventureWorks2012 DB. How exactly should I do this for all the tables in the whole database ? What I have written below is just for one of the tables, is there a quicker way to do it for all tables
    in this DB so that it performs the actions mentioned above, automatically ? Help would be greatly appreciated so I can understand how this works, thanks
    CREATE TRIGGER [HumanResources].[tr_HumanResources_AfterUpdate]
    ON [AdventureWorks2012].[HumanResources].[Department]
    AFTER UPDATE
    AS
    BEGIN
    SET NOCOUNT ON;
    UPDATE AdventureWorks2012_new.HumanResources.Department
    SET Name = t2.Name,
    GroupName = t2.GroupName,
    ModifiedDate = t2.ModifiedDate
    FROM AdventureWorks2012.HumanResources.Department AS t2
    INNER JOIN AdventureWorks2012_new.HumanResources.Department AS t1
    ON t2.DepartmentID = t1.DepartmentID
    END

    For insert it's easy:
    CREATE TRIGGER [HumanResources].[tr_HumanResources_AfterInsert]
    ON [AdventureWorks2012].[HumanResources].[Department]
    AFTER INSERT
    AS
    BEGIN
    SET NOCOUNT ON;
    Insert INTO AdventureWorks2012_new.HumanResources.Department
    (DepartmentID, Name, GroupName, ModifiedDate)
    SELECT DepartmentID, Name, GroupName, ModifiedDate
    FROM Inserted;
    END
    I didn't verify column names, so you may need to make sure to use correct column names for that table.
    Setting replication is a bit advanced topic although BOL is clear and you may start here
    http://technet.microsoft.com/en-us/library/ms151198.aspx
    If it will be complicated for you, you can ask extra questions in the MSDN Replication forum.
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

  • Update/insert/delete data from xcelsius to Database via web service

    Hi,
    I need to create dashboard that go function can <b>update/insert/delete</b> data send to <u>Database</u> thru <u>web services</u>, as i know got 2 xcelsius add-on software which support those of function <b>InfoBurst</b> and <b>flynet </b>
    <b>InfoBurst</b>
    http://www.infosol.com/azbocug/minutes/4-Writeback%20to%20a%20Database%20with%20Xcelsius.pdf
    <b>flynet </b>
    http://www.flynetviewer.com/public/community/Blogs/FlynetXcelsiusServerUser/default.aspx
    Except this 2 purchase add-on xcelsius, any other solution ?  
    Maybe need to write some in MSSQL or C# programming which enable insert, update, delete ...etc  ?
    *note: i not use Xcelsius Engage Server , i use Xcelsius Engage only
    thanks,
    regards
    s1
    Edited by: Leong Pui Kee on Mar 1, 2011 6:06 AM

    Hi,
    As of now in Xcelsius/Dashboard Design there is no feature or functionality to insert/update/delete data from database.
    Solution:
    Create a Web service in let’s say C# or Java, which will perform insert/update/delete operation.
    In Xcelsius add Web Service connection and user above web service.
    Xcelsius Web Service connection provides option to pass input values to a Web Service (Input Pane) and get the result (Output values pane).
    We can pass values to be written to the database as a input to Web Service via Web Service connection from Xcelsius and write data to the database.
    Note:
    Performing delete operation from Xcelsius Dashboard could be risky and may delete important data from database. I would not prefer giving delete option/functionality in Xcelsius dashboard.
    Hope this helps!
    Thank you.
    Regards,
    Vinay Mhaske

  • Update/Insert/Delete into the same table

    Hi,
    I'm writing pl/sql code :
    nvoice_id will be passed as parameter and based on invoice_id I need to see whether any records exist in history table.If not any then insert record into table.If more than one record exist then I need delete all except most recent one based hist_seq column in that table.
    Then I need to update that record for description column .How to put dml operation one after another in an efficient manner?As one statement depend on another do I need to use autonomous transaction?
    Thanks,
    Kiran

    user518071 wrote:
    Hi,
    I'm writing pl/sql code :
    nvoice_id will be passed as parameter and based on invoice_id I need to see whether any records exist in history table.If not any then insert record into table.If more than one record exist then I need delete all except most recent one based hist_seq column in that table.
    Then I need to update that record for description column .How to put dml operation one after another in an efficient manner?As one statement depend on another do I need to use autonomous transaction?
    Thanks,
    KiranBasic idea.
    create procedure p_deal_with_invoice
       p_invoice_id  number
       l_max_hist_seq number;
    is
    begin
    select max(hist_seq)
    into l_max_hist_seq
    from your_table
    where invoice_id = p_invoice_id;
    if l_max_hist_seq is not null
    then
       delete from your_table
       where invoice_id = p_invoice_id
       and hist_seq != l_max_hist_seq;
       update your_table set some_columns = some_new_value
       where invoice_id = p_invoice_id
       and hist_seq = l_max_hist_seq;
    else
       insert into your_table () values ();
    end if;
    end p_deal_with_invoice;
    /An autonomous transaction would probably be the last thing you'd want here. Just a simple plsql procedure that accepts a INVOICE_ID as an input.
    Cheers,
    Edited by: Tubby on Jun 18, 2012 2:53 PM

  • Materialized Views: how can I find the number of updates, inserts, delete

    We are using Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Prod.
    In a materialized view, with fast incremental refresh, done after every 5 minutes automatically, I want to store in a logging table the number of rows inserted,updated and deleted in the materialized view by that refresh.
    One option is to create a job that should read the materialized view log table just before the refresh and store the required information in the logging table. But this information may not be accurate.
    Is there any other way to collect this information for each refresh?

    Use auditing, or an before insert/update/delete trigger, that updates a counter
    I hate myself for giving this advice, because it will bring you problems, with the MV update/refresh speed, table lock contention on the log-table....
    Be carefull !!
    Why not use auditing on the source table and why does anyone wants to know the number of changes??
    Regards
    FJFranken

  • How to create a stored procedure that contains all 3 AFTER Triggers Update/Insert/Delete ?

    Hi guys, I'm trying to create a Stored procedure that will automatically add all 3 After triggers when executed on any given database, can someone please explain and give an example on how do I go about doing this ? I'd also like it to raise any errors
    that may come across, thanks in advance.

    Lets start with the question why do you need the triggers at all. Since SQL Server 2005 we can use an OUTPUT clause.
    This code can be re-written in SQL Server 2005 using the OUTPUT clause like below:
    create table itest ( i int identity not null primary key, j int not null unique )
    create table #new ( i int not null, j int not null)
    insert into itest (j)
    output inserted.i, inserted.j into #new
    select o.object_id from sys.objects as o
    select * from #new
    drop table #new, itest;
    go
    Now from this example, you can see the integration of OUTPUT clause with existing DML syntax.
    Another common scenario is auditing of data in a table using triggers. In this case, the trigger uses information from the inserted and updated tables to add rows into the audit tables. The example below shows code that uses OUTPUT clause in UPDATE and DELETE
    statements to insert rows into an audit table.
    create table t ( i int not null );
    create table t_audit ( old_i int not null, new_i int null );
    insert into t (i) values( 1 );
    insert into t (i) values( 2 );
    update t
       set i  = i + 1
    output deleted.i, inserted.i into t_audit
     where i = 1;
    delete from t
    output deleted.i, NULL into t_audit
     where i = 2;
    select * from t;
    select * from t_audit;
    drop table t, t_audit;
    go
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Updated, inserted, deleted records

    Hello,
    Oracle 10g R 2
    Is there anyway to find the updated, deleted, or inserted records in a table?
    Regards,

    NB wrote:
    i need to log all the modifications done on table, (update, delete or insert) in another table
    is there any thing to give me all the modified records, for example between sysdate -1 and sysdate?If you have a copy of "previous" data and the "current" data then you can use SQL set operations (MINUS, INTERSECT etc.) to determine which data has been inserted, updated and deleted.
    If you don't actually record the inserts, updates and deletes as they happen, there is some possibility of using the archive logging of the database and then log mining to find out what happened to the data, but that data is only available for a limited time (assuming archive logging is enabled for the tables).
    Essentially, if you don't have a historic copy of the data and you don't record the changes as they happen yourself, getting the information is going to be very tricky.

  • Update/insert/delete in the same JSP

    Dear all,
    i want to develop a same JSP from which can update,delete or insert..is it possible??
    thanks in advance..
    sinar

    The form display is dictated by how you process the submit. I would build the form by using standard html tags. Here is another pseudo example:
    <FORM ACTION="target.jsp" >
    <TABLE>
    <TR>
    <TD>
    DeptNo
    </TD>
    <TD>
    DName
    </TD>
    <TR>
    <%
    int nRow = 0;
    %>
    <jbo:RowsetIterate datasource="ds">
    <%
    // increment the row number
    nRow++;
    String sDeptno = "Deptno" + nRow;
    String sDname = "Dname" + nRow;
    String sRowKey = "RowKey" + nRow;
    %>
    <jbo:Row id="myrow" action="current">
    <TR>
    <TD>
    <input type="text" name="<%=sDeptno%>" value='<jbo:ShowValue dataitem="Deptno" />' />
    </TD>
    <TD>
    <input type="text" name="<%=sDname%>" value='<jbo:ShowValue dataitem="Dname" />' />
    <input type="text" name="<%=sRowKey%>" value='<jbo:ShowValue dataitem="RowKey" />' />
    </TD>
    <TR>
    </jbo:Row>
    </jbo:RowsetIterate>
    <input type="submit" />
    </TABLE>
    </FORM>
    NOTE: This should get you started!!!

  • Update & Insert into Internal table

    Dear Abapers,
    Is it possible to update a entry in the internal table if exists, otherwise inserts a new one.
    I think MODIFY <Internal Table> will not insert new one if the matching entry is not there.
    MODIFY <database_table> have this facility.
    Thanks in advance,
    Satish

    Hi,
    i dont know what type of fields u r having but about collect statement i am correct
    The following special statement allows you to summate entries in an internal table:
    COLLECT wa INTO itab.
    itab must have a flat line type, and all of the fields that are not part of the table key must have a numeric type (f, i, p). You specify the line wathat you want to add as a work area that is compatible with the line type of itab.
    When the line is inserted, the system checks whether there is already a table entry that matches the key. If there is no corresponding entry already in the table, the COLLECT statement has the same effect as inserting the new line. If an entry with the same key already exists, the COLLECT statement does not append a new line, but adds the contents of the numeric fields in the work area to the contents of the numeric fields in the existing entry.
    REPORT demo_int_tables_COLLECT .
    DATA: BEGIN OF line,
    col1(3) TYPE c,
    col2(2) TYPE n,
    col3 TYPE i,
    END OF line.
    DATA itab LIKE SORTED TABLE OF line
    WITH NON-UNIQUE KEY col1 col2.
    line-col1 = 'abc'. line-col2 = '12'. line-col3 = 3.
    COLLECT line INTO itab.
    WRITE / sy-tabix.
    line-col1 = 'def'. line-col2 = '34'. line-col3 = 5.
    COLLECT line INTO itab.
    WRITE / sy-tabix.
    line-col1 = 'abc'. line-col2 = '12'. line-col3 = 7.
    COLLECT line INTO itab.
    WRITE / sy-tabix.
    LOOP AT itab INTO line.
    WRITE: / line-col1, line-col2, line-col3.
    ENDLOOP.
    The list output is:
    1
    2
    1
    abc 12 10
    def 34 5
    The example fills a sorted table. The first two COLLECT statements work like normal insertion statements. In the third COLLECTstatement, the first line of itab is modified.
    Regards

  • Update/Insert/Delete/Select Monitoring?

    Hello,
    is it possible to monitor user activity like upper mentioned statements and how can I realize that?
    The information about the user-activity should be shown for each tables within a database.
    Regards

    Steve wrote:
    Ok thanks a lot.
    Is it also possible to audit procedures and views?Sure. Check the following link:
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_4007.htm#i2059073
    Kamran Agayev A.
    Oracle ACE
    My Oracle Video Tutorials - http://kamranagayev.wordpress.com/oracle-video-tutorials/

  • Insert,update and delete data in a table using webdynpro for abap

    Dear All,
    I have a requirement to create a table allowing the user to add rows in it and update a row as well as delete a row from that table.To do this I guess I have to make use of ALV.But using ALV I am not able to enter data to a table where as I can make a column editable delete a row etc. please guide me to perform these operations(insert,update and delete) on table.
    Thanks,
    Reddy.

    Hi Sridhar,
    By using ALV you can do all insert delete etc things. if you want to edit i mean you can yenter data in ALV.
    Check this...
    http://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/3133474a-0801-0010-d692-81827814a5a1
    Editing alv in web dynpro
    editing rows in alv reports
    Re: editing rows and columns in alv reports in webdynpro abap
    Cheers,
    Kris.

  • Can we have an example of using update, insert, and delete stored procedure

    I would like to see an example of using retrieve (return resultset), update, insert, and delete stored procedures in JSF. I need to see syntax how JSF can call those stored procedures. This option is absolutely important when building web-application. Currently, I haven't found resource to do for this purpose yet. The database can be any such Oracle, DB2, pointbase, etc that support stored procedures.
    Anyone knows?
    Thanks,
    Tue Vu

    Hi ttv,
    I asked around a bit and here's some more info:
    To bind a ResultSet to a read only Data Table component just set the "value" property of the Data Table component to point at it, and JSF will synthesize a DataModel around it.
    * Note that because we can't call the stored procedure at design time, Creator can't do the fancy table layout stuff it does for rowsets. You'll need to hand craft the columns just like the Google Client example.
    * As I mentioned previously, you will have to manually code the stored procedure access in your java code - see the code clip I mentioned in previous reply (and if this is via a stored procedure, then any textbook about JDBC will undoubtedly have examples). Simplest way might be a getter method on the page bean that contains the call to the stored procedure and returns the resulting ResultSet object.
    * Don't forget to close the result set - we typically do this at the end of the request (i.e. add a close in the afterRenderResponse() method.
    * Don't throw exceptions - or if you have to, make sure you close the result set in a finally clause (thrown exceptions bypass the afterRenderResponse method in the lifecycle).
    * You give up on the caching provided by our RowSetDataModel (which can't be connected to a ResultSet even manually), so I would recommend that you only use datatables to display the data and then go to a single row page to do edits/deletes (similar to the TwoPage example in AppModel and the Update, Insert Delete tutorial).
    And yes please do submit an example - we will gladly post it!!! :) The best way to submit this kind of thing would be through:
    http://developers.sun.com/prodtech/javatools/jscreator/reference/codesamples/sampleapps.html
    on the right side, Related Links, under Creator Heros, click Submit Content and there you can send it in!
    Hope this helps!
    Val

  • How do I update/insert into a target table, rows after date X

    Hi all
    I have a mapping from source table A to target table B. Identical table structure.
    Target table A updates rows and inserts rows daily. Every week I want to synchronize this with table B.
    I have CREATION_DATE and LAST_UPDATE_DATE on both tables. I want to pass in a parameter to this mapping of date X which tells the mapping:
    "if CREATION_DATE is past X then do an insert of this row in B, if LAST_UPDATE_DATE is past X then do an update of this row in B"
    Please can you help me work out how to map this correctly as I am new to OWB.
    Many thanks
    Adi

    Hi,
    You can achieve this by -
    1. Create a control table, say Control_Table, with structure
    Map Name, last_load_date. Populate this table with the mappings that synchronizes your Table B.
    2. Alter mapping, that loads Table B to use the above control table to get all the records from Table A, you have to join Table A and Control_Table with the condition -
    Control_Table.Map_Name = < mapping name>
    AND ( TableA.Creation_Date > Control_Table.last_load_date
    OR TableA.Last_Update_Date > Control_Table.last_load_date )
    3. Then use UPDATE/INSERT on the Table B based on the Keys. This should take care of INSERT ( if not present) / UPDATE (if the row already exists).
    4. Schedule the mapping to run on weekly basis.
    5. You have to maintain the Control_Table to keep changing the values for Last_Load_Date to pick the data since the last time Table B is synchronized.
    HTH
    Mahesh

  • Transaction which updates/insert table KNVS

    HI all,
           can some one tell me the transaction/path which updates/insert records in table KNVS.
           or
          how and where the forwarding agent for the customer(Sold To) is maintained.
          i have added forwarding agent in XD02 but the record was not updated in KNVS.
    plz help....... or suggest other option.
    Regards,
    Sandip

    Hi Sandip,
    If you maintained the forwarding agent as a partner function in the sales area data tab of the customer master, then you'll find the corresponding entry in table KNVP (field LIFNR). Note that on database level the partner functions are stored in German, so when you check the table via SE16N make sure that you have conversion exits applied. In English the partner function is 'FA', whereas on database level one would need to read it via 'SP' (German word Spediteur which corresponds to forwarding agent).
    Best wishes, harald

  • XSQL updates and deletes

    Hello
    I can insert records in a table using the xsql but am unable to update and delete from tables using xsql ....
    need help its urgent ..
    can anyone mail me some sample code for xsql update and delete ...
    thank u
    null

    If you're using BC4J and XSQL together, then you can leverage the oracle.jbo.xsql.UpdateViewObject action handler that ships with BC4J for use in XSQL pages to make it easy to handle hierarchical XML documents using BC4J view objects.
    BC4J view objects can both produce and consume XML documentment using the writeXML() and readXML() API's on oracle.jbo.ViewObject, respectively.
    If there are view links in place, then the BC4J XML processing mechanism follows these links to nested, detail information. When you "feed" an existing XML document to the YourViewObject.readXML() method, it automatically processes inserts, updates, and deletes, as well as apply any BC4J business logic that exists in your Entity Objects (if any).
    The BC4J Action Handlers make it easy to combine BC4J with XSQL pages without having to write the writeXML() and readXML() calls by hand.

Maybe you are looking for