Proper Deletion of Records for many to many relationships

Hello Pros, Need advice for best practice on following scenario. This is just an example based on my actual needs.
People Table -> PeopleJoinAddress Table-> Address Table
  1 | John                 1 | 1                            
1 | Address 1
 2 |  Betty                2 | 1                             
ok, scenario is people can have many address's and address can be for many people(like a household)
When Deleting A Person , First Thought using cascading would delete address for other people, so should I consider looping with a while loop or cursor to delete just the join link if address exists for more then one, If not then delete
address also. Or should I consider doing that from application side and the just make call to simple  database Stored Procedures as needed 

CREATE TABLE Personnel
(emp_id CHAR(10) NOT NULL PRIMARY KEY,
CREATE TABLE Addresses --- standard address numbers
(san CHAR(10) NOT NULL PRIMARY KEY,
CREATE TABLE Households
(emp_id CHAR(10) NOT NULL 
 REFERENCES Personnel(emp_id)
 ON DELETE CASCADE,
 san CHAR(10) NOT NULL 
 REFERENCES Addresses(san)
 ON DELETE CASCADE,
PRIMARY KEY (emp_id, san),
>> When deleting an employee, first thought using cascading would delete address for other people, .. <<
No. You delete the employee in the Personnel table, its reference in the Households is cascaded but the Addresses table is not touched. 
>> so should I consider looping with a while loop or cursor to delete just the join link [sic] if address exists for more than one, If not then delete address also. <<
Saying “loops” and “cursors” to an SQL programmer is like saying “fried babies” to a Vegan – wrong in so many ways :) Also RDBMS has no links! That is a term for pointers used in 1970's Network Databases. 
An address can have nobody living there and we are fine. If you want to clean out empty addresses, you can do this with a trigger, a garbage keeping procedure that you run once a year or use VIEWs. What is the best business rule for you? 
>> Or should I consider doing that from application side and the just make call to simple  database Stored Procedures as needed  <<
No. Which application? You could have hundreds of them.  A business rule should be enforced one way, one time and in one place.  
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL

Similar Messages

  • FM or BAPI for creating/deleting condition records for an output type

    Hi all,
               what is the FM or BAPI for creating and deleting the condition records for a Z(custom) output type.

    You can use trasaction SXDA_TOOLS.....
    object type BUS3003
    program type BINP
    program/method RM06IBI0
    but the fields must be sequentially written in the txt, with every space inclusive....

  • How to delete PSA records for test

    Dear Consultants,
    There ars  some  records  in  PSA, now in order to test ETL  I  want to  delete  a part  of records  from  PSA.
    For example ,there are  100  records in PSA,  I  want to  delete  30  records  from  PSA.
    But  i  can  not  delete  records  from PSA.
    Please give me some proposals and methods  to  delete  records  from  PSA.
    Thanks a lot & Best Regards
    Ricky

    Hello,
    Why not delete the request and load again with restricted InfoPackage? Or use DTP with restriction for further loading.
    If you really want to do this, first get the technical name of the PSA, say it's /BIC/B00000111.
    Then create an InfoPackage, and set a selection field as type 6(abap routine), double click it and key in the following statement:
    delete from /BIC/B00000111 where fielda = 'AA' and REQUEST = 'REQU_XXXXX'.
    Then test run the InfoPackage. Wait for a while and corresponding records will be deleted.
    Regards,
    Frank

  • Delete the record

    Hi folks,
    I am trying to delete a record from pa0019. Of course I am not deleting the record directly but copying the existing record into the workarea and deletingit.
    However, query of selecting the record from table is not working.
    tables: pa0019.
    data: wa_pa0019 like pa0019 occurs 0 with header line.
    select single * from pa0019 into wa_pa0019 where pernr = 'v_pernr'
    and tmart = 'Z9' and termn = '07/07/2005'.
    delete pa0019 from wa_pa0019.
    I see a record for this employeeid in the table pa0019. why is not retrieving any record?  Am I missing something here?
    I know this is simple, and have done this before too, but not able to recall what is the problem here?
    Any thoughts,
    Thanks,
    SK

    Global variables inthe program
    DATA : RETURN LIKE BAPIRETURN1.
    DATA : KEY LIKE BAPIPAKEY.
    DATA : RETURNE LIKE BAPIRETURN1.
    data: begin of itab1 occurs 0,
                employee(8),
                reason_type(2),
                reason_code(2),
                return_date like sy-datum,
    end of itab1.
    I read the data into the internal table from an external text file, then I upload the record(RLOA) into actions infotype using BDC session, then I need to delete the record for the same employee in 0019.
    I think I am missing the RECORD parameter, hwo can i get that?
    loop at itab1.
    *** check to see whether there is a RLOA record for the employee
      select single * from pa0000 where pernr = itab1-employee and
           massn = 'z7' and begda = itab1-return_date.
    if sy-subrc = 0.
          error-employee = itab1-employee.
          error-reason = 'RLOA exists for the employee'.
          append error.
          continue.
        else.
        clear bdcdata.
        refresh bdcdata.
        perform load_data.
    If the RLOA record is created in Actions infotype delete
    the record in monitoring of tasks record in IT0019
         if g_monitoringflag = 'X'.
    format the date to mm/dd/yyyy
            v_returndate = itab1-return_date.
            concatenate v_returndate0(2) '/' v_returndate2(2) '/'
            v_returndate+4(4) into v_formatdate.
        CALL FUNCTION 'BAPI_EMPLOYEE_ENQUEUE'
           EXPORTING
            NUMBER = itab1-employee
           IMPORTING
            RETURN = RETURNE.
        CALL FUNCTION 'HR_INFOTYPE_OPERATION'
           EXPORTING
             INFTY = '0019'
             NUMBER = itab1-employee
             SUBTYPE = 'Z9'
             VALIDITYEND = itab1-return_date
             VALIDITYBEGIN = itab1-return_date
             TMART ='Z9'
             TERMN = itab1-return_date
             OPERATION = 'DEL'
            TCLAS = 'A'
             DIALOG_MODE = '0'
         IMPORTING
            RETURN = RETURN
            KEY = KEY.
         IF RETURN IS NOT INITIAL.
           WRITE :/ 'Error Occurred'.
         ENDIF.
         CALL FUNCTION 'BAPI_EMPLOYEE_DEQUEUE'
           EXPORTING
           NUMBER = itab1-employee.
          if sy-subrc = 0.
               clear:g_monitoringflag, v_formatdate.
               else.
              error-employee = itab1-employee.
              error-reason = 'No record created for RLOA'.
              clear:v_formatdate.
           endif.
         endif.
      endif.
    endloop.
    Thanks in advance for your help.
    SK

  • Upgraded to new MacBook and now Office activation is declined because of too many users.  How do I delete Office registration for my old computer?

    Help please.  I upgraded to a new macbook and migrated everything.  However, Office will not activate because it says too many copies are active.  How do I delete the activiation for my old laptop?  Thanks.

    Use the Office activation phone number and call the automated activation menu. It will ask you how many installations you have. It will then issue you a new code for your new installation. Make sure your old installation is removed.

  • Delete messages stuck in status 12, Recorded for Outbound Processing

    I am on a PI 7.10 SP8 system.  I have 59,000 XML messages showing in status 12 ( Recorded for Outbound Processing) that I would like to just delete or cancel.  These have accumulated over several days of testing interfaces.  If I have to allow them to be processed, that would also work but is not needed.  I have read about 6 different forum threads and tried several things but nothing has worked yet. <br>
      The messages can not be cancelled from SXMB_MONI. <br>
      The queues are no longer showing in SMQ2.   <br>
      I have tried restarting and re-registering the queues. <br>
      I've tried RSXMB_RESTART_MESSAGES and RSXMB_CANCEL_MESSAGES. <br>
      SWPR & SWPC show nothing to restart. <br>
    Any ideas on something else to try? <br>

    Hi,
    You can try to delete or archive mesages. use following links.
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/402fae48-0601-0010-3088-85c46a236f50
    Delete Messages SXMB_MONI
    http://help.sap.com/saphelp_nw04/helpdata/en/0e/80553b4d53273de10000000a114084/frameset.htm
    Too many questions on Archive/Delete messages.
    Inder

  • WCF RIA entity Update from Lightswitch for Many to many relationship

    I have two entities which have many to many relationship. I need to create a screen to update data from both the tables simultaneously using a screen. So I used First as a sql database entity in Lightswitch second is RIA service Entity(Which is junction table).
    both tables are editable in a same screen but when I click on Save button,
    System call to
    [Query(IsDefault = true)]public IEnumerable<EquipmentJob> SelectFakeJobs()  
    method instead of calling
    [Query]public IEnumerable<EquipmentJob> SelectJobs(long? ID).
    I am using the Ria table as a query in my screen and setting the parameter as a table1.SelectedItem.ID.  But after click on save it does not call to parameterized
    method to get data. I have already implemented the 'Saving' method.  It gives following exception.
    Only changes to a single data service can be saved.  To save changes to multiple data services, implement the "Saving" method.
    Data conflict. another user has deleted the record.
    I followed following link to setup the Many to Many relationship update in LightSwitch
    http://powerbala.com/many-to-many-control-for-microsoft-lightswitch/

    Only changes to a single data service can be saved.  To save changes to multiple data services, implement the "Saving" method.
     This issue is discussed before, generally you need implement the <ScreenName>_InitializeDataWorkspace method and add the data services that you'd like to save to the saveChangesTo list.
    https://social.msdn.microsoft.com/Forums/en-US/238e5e91-8598-42f9-817d-12b6f5b980a1/having-a-problem-saving-getting-error?forum=lightswitch

  • Customized delta data source for deleting data record in the source system.

    Hello Gurus,
           there is a customized delta data source,  how to implement delta function for deleting data record in the source system?
    I mean if there is record deleted in the source sytem, how to notify SAP BW system for this deleting change by this customized delta
    data source?
    Many thanks.

    Hi,
    when ever record deleted we need to write the code to insert the record in  Z table load this records into BW in a cube with similar structure.while loading into this cube multiply the Keyfigure by -1.
    add this cube in the Multi Provider.The union of the records in the orginal cube and the cube having deleted records will result in zero vale and will not be displayed in report .
    Regards,

  • Is there a phone number to call Adobe.  I go around an endless loop pressing their contact info tabs?  Maybe someone at this sight can help. I am new to digital photo - I have been a B&W film photographer for many years. I have a problem with a Macbook Ai

    Is there a phone number to call Adobe.  I go around an endless loop pressing their contact info tabs?  Maybe someone at this sight can help. I am new to digital photo - I have been a B&W film photographer for many years. I have a problem with a Macbook Air.  It was working fine - I was using LR and a message came on the screen that said something like the memory was dangerously low.  I stopped and tried to delete LR files.  I couldn't do it.  I closed the program and tried reopening and got the message that there is not enough memory available to open LR.  I contacted Apple.  They spent a half hour on the phone with me and eventually told me they didn't know how to help. The tech said that LR had gobbled up all the memory and said I should contact Adobe and ask where and how my photo files are stored and to delete them.  I have several back-ups.  Thanks - Arthur

    This sort of error message only comes up for Lightroom when your hard disk is full. Indeed this has nothing to do with internal memory as that will be intelligently be dealt with. If you have a mac Book Air that is not so surprising as the cheapest versions come with very small hard disks and if you shoot raw with any recent camera, you'll fill up your hard disk very quickly and you can probably only store a few months of pictures if you are a typical photographer. So the bottom line is that you need to create some room on your hard disk. You should move some of your originals to an external hard disk. You can also delete some of your backup copies of your catalog file that Lightroom automatically generates every few days and that quickly gobble up hard disk space. So first figure out how full your hard disk is. To see that, go to the apple menu, hit -> About this Mac -> More info->Storage. You should see your internal hard disk on top and you'll find that it is almost entirely full with photos. Now find your Lightroom catalog file using Finder. It is usually in a folder in the Pictures folder in your home directory. You should see a Lightroom 5 Catalog.lrcat file, a previews file and a folder called backups. Inside the backups folder, you'll find a lot of subfolders. They have names that show the dates the backups were created. If you have backups of your entire hard disk, you can delete these backups when they are older than a few months. I usually only keep the last 4 around. Just drag the folders into the trash can on the dock on the bottom of your screen and empty the trash. This will probably free up enough space that Lightroom will already run again. Now start thinking about where you will want to store older images. If you have a good USB3 or Thunderbolt hard disk that is probably the best option. There is a video here by Adobe that has some instructions on how to do this: Is Your Hard Drive Full? Here’s How to Move Images to Another Drive in Lightroom. « Julieanne Kost's Blog If that doesn't work because you don't have enough hard drive space to run Lightroom yet, here is another set of instructions to move your files using the finder to the other hard disk: How do I move only my photos to another hard drive, leaving the catalog where it is? - The Lightroom Queen. If you follow that, as soon as you confirm all your images are on the new hard disk, you can delete them from your internal one. She is not so clear about that part but if you don't delete the originals that you moved off you don't free up space. You should move the folder structure over to the new hard disk and then reconnect the folders in Lightroom. That should make it refind all your images.
    That said, if you are uncomfortable with the computer in itself, your best bet is to find a local photography club. There is invariably a Lightroom savvy person in there that could help you move your files. That might be your best bet if you are uncomfortable moving these yourself. A general mac savvy person like you would find at an Apple store or so generally will not be able to help you with this except when they are photographers themselves and know Lightroom. You might get lucky with that.

  • I need advise and help with this problem . First , I have been with Mac for many years ( 14 to be exact ) I do have some knowledge and understanding of Apple product . At the present time I'm having lots of problems with the router so I was looking in to

    I need advise and help with this problem .
    First , I have been with Mac for many years ( 14 to be exact ) I do have some knowledge and understanding of Apple product .
    At the present time I'm having lots of problems with the router so I was looking in to some info , and come across one web site regarding : port forwarding , IP addresses .
    In my frustration , amongst lots of open web pages tutorials and other useless information , I come across innocent looking link and software to installed called Genieo , which suppose to help with any router .
    Software ask for permission to install , and about 30 % in , my instinct was telling me , there is something not right . I stop installation . Delete everything , look for any
    trace in Spotlight , Library . Nothing could be find .
    Now , every time I open Safari , Firefox or Chrome , it will open in my home page , but when I start looking for something in steed of Google page , there is
    ''search.genieo.com'' page acting like a Google . I try again to get raid of this but I can not find solution .
    With more research , again using genieo.com search eng. there is lots of articles and warnings . From that I learn do not use uninstall software , because doing this will install more things where it come from.
    I do have AppleCare support but its to late to phone them , so maybe there some people with knowledge , how to get this of my computer
    Any help is welcome , English is my learned language , you may notice this , so I'm not that quick with the respond

    Genieo definitely doesn't help with your router. It's just adware, and has no benefit to you at all. They scammed you so that they could display their ads on your computer.
    To remove it, see:
    http://www.thesafemac.com/arg-genieo/
    Do not use the Genieo uninstaller!

  • Invoice output Condition type not populated for many invoice documents

    Hi Guru's
    Invoice  Out put Condition  type for printing  not populated in the invoice document. Now We need to insert condition type for many  documents to print at a time. We can manually place condition type  at document header level individually for every document. But we have many documents to print.
    plz advice me how to print all these documents
    Thanks in advance.
    Regards,
    Ravikanth

    Hi Ravi
    Just take help from your ABAP team. Record the event in SHDB ask then to get invoice number from excel file and loop the program.
    This will be more faster then LSMW.
    I am giving you BDC code
    report ZBILVF02
           no standard page heading line-size 255.
    include bdcrecx1.
    start-of-selection.
    perform open_group.
    perform bdc_dynpro      using 'SAPMV60A' '0101'.
    perform bdc_field       using 'BDC_CURSOR'
                                  'VBRK-VBELN'.
    perform bdc_field       using 'BDC_OKCODE'
                                  '/00'.
    perform bdc_field       using 'VBRK-VBELN'
                                  '90010310'.
    perform bdc_dynpro      using 'SAPMV60A' '0104'.
    perform bdc_field       using 'BDC_CURSOR'
                                  'VBRK-FKART'.
    perform bdc_field       using 'BDC_OKCODE'
                                  '=SICH'.
    perform bdc_transaction using 'VF02'.
    perform close_group.
    Regards
    Vijay

  • [ADF] Adding/deleting entries in a many-to-many relationship

    I am using JDeveloper 10.1.3 and the ADF BC / ADF Model / ADF Faces / JSF technology stack.
    For this question, I am using the SRDemo application as an example, specifically the many-to-many relationship between USERS and PRODUCTS (the Staff Expertise relationship), outlined in red in this schema diagram: Image Link
    Users may have any number of product expertise areas and many users may have the same product expertise area. For the purposes of this example I have added two reference fields from the PRODUCT table into the ExpertiseAreas VO (Name and Description), outlined in red in this data control palette section: Image Link
    I have created a page which shows the details of a user (1), along with a table showing the expertise areas the user has (3), and a table of all the products available (2), numbered on this design page: Image Link and corresponding to the numbered data controls on this data control palette section: Image Link, where 1 is rendered as an ADF Read-only Form, 2 is an ADF Read-only Table with a tableSelectMany element in the selection facet, and 3 is also an ADF Read-only Table.
    What I am trying to do is have the tableSelectMany element reflect which of the products are linked to the current user in the expertise areas relationship (by having the checkbox for currently linked products checked), and when you check or uncheck a product's checkbox, it should add or remove the row in the EXPERTISE_AREAS intersection table, respectively (asume for this example that there are default values for Expertise Level and Notes).
    So far I have been following the process used in section 19.8 of the ADF Developer's Guide for Forms/4GL Developers, which describes how to set up a selectManyShuttle which implements the adding and deleting functionality. So I have a Client Interface method in the Application Module, updateSkillsForCurrentStaff (described in section 10.6.7.2), and I have a selection listener for the assignment table in the backing bean for the page, which calls the updateSkillsForCurrentStaff method:
    public void selectionChanged(SelectionEvent event)
      BindingContainer bc = getBindings();
      DCIteratorBinding productsIB = (DCIteratorBinding)bc.get("ProductListIterator");
      Set keys = getTable1().getSelectionState().getKeySet();
      Iterator iter = keys.iterator();
      List productIds = new Vector();
      while (iter.hasNext())
        String product = ((Key)iter.next()).toStringFormat(true);
        productsIB.setCurrentRowWithKey(product);
        ViewRowImpl productRow = (ViewRowImpl)productsIB.getCurrentRow();
        Number productId = (Number)productRow.getAttribute("Id");
        productIds.add(productId);
      OperationBinding ob = bc.getOperationBinding("updateSkillsForCurrentStaff");
      Map pm = ob.getParamsMap();
      pm.put("productIds", productIds);
      ob.execute();
    All of this works, but I can't work out how to link the selection state of the assignment table to the expertise areas that are linked to the user. Also I think the method listing above must be a bit of a hack, but I don't know enough about this to know if there's an easier way of doing it.
    Any help is appreciated.

    Have a look at this example I cooked up for you.
    http://radio.weblogs.com/0118231/2006/10/03.html#a739
    It might not be the first way one thinks to implement something, but it illustrates a very interesting, model-centric approach to the problem you propose.
    My feelings won't be hurt if you prefer a more view-centric approach, but I wanted to illustrate what was a maximally-model-centric solution (in fact, which doesn't even require a backing bean!) If you like a more view-centric approach, I can help you figure out what's wrong with your key-handling above. For one, I would probably start by passing the Set of Key's directly to the middle tier application module method to eliminate client-side code.
    Check it out and let me know what you think. Try it directly in the Business Components Tester to appreciate one of the benefits a model-centric solution can bring.

  • When reading my book on iBooks, I encounter duplicate pages for many pages then it skips the pages that should be there so I am missing large parts to chapters, is this a "bug" in the book or app? How can this be fixed?

    When reading my book on iBooks, I encounter duplicate pages for many pages then it skips the pages that should be there so I am missing large parts to chapters, is this a "bug" in the book or app? How can this be fixed?

    Does the same thing happen on any other books that you have in the app ? If not then it's probably just that one book, in which can you could try deleting the book and re-downloading it - if it re-downloads in the same state then try the 'report a problem' from your purchase history :http://support.apple.com/kb/HT1933

  • After R12 Upgrade: No records in many of the tables.

    Hi all,
    After R12 upgrade, we found there are no records in many tables. For example AR_BATCHES_V.
    What could be the probable causes?
    Also, note that there are still some concurrent requests running.
    DQM Parallel Sync Index Child Program2 (DQM Parallel Sync Index Child Program)
    Synchronize Workflow LOCAL tables (Report Set)
    Process Benefits Data Conversion
    S. Sundar

    Hi,
    I'm a bit late to the party in this thread, but:
    Are most of the unpopulated tables related to Financials? With the introduction of E-Business Tax (ZX) and Sub-Ledger Accounting in R12, some data seems to have been moved to other tables and schemas. For example, we had some reports that needed to be rewritten for R12 because some Receivables tables and views were empty after the upgrade. I don't get into the functional side of things very often, so I don't know if AR is similarly affected.
    Sorry I don't have much detail to offer, but maybe this will give you a starting point for further research.
    Regards,
    John P.

  • Uploading data in standard infotype for many pernrs.

    how to upload data for many pernrs through a single fm in a standard infotype ????
    please help me...

    CALL FUNCTION 'HR_INFOTYPE_OPERATION'
          EXPORTING
            INFTY                  = '2010'
            NUMBER                 = P2010-pernr "wa_ot_calc-pernr
            VALIDITYEND            = P2010-endda "wa_ot_calc-zotdate
            VALIDITYBEGIN          = P2010-begda "wa_ot_calc-zotdate
            RECORD                 = P2010
            OPERATION              = 'INS'
            DIALOG_MODE            = '0'
            NOCOMMIT               = 'X'
         IMPORTING
            RETURN                 = BAPISUBRC.
        IF SY-SUBRC <> 0 OR
           NOT BAPISUBRC IS INITIAL.
          MESSAGE ID  BAPISUBRC-ID
                TYPE  BAPISUBRC-TYPE
              NUMBER  BAPISUBRC-NUMBER
                WITH  BAPISUBRC-MESSAGE_V1
                      BAPISUBRC-MESSAGE_V2
                      BAPISUBRC-MESSAGE_V3
                      BAPISUBRC-MESSAGE_V4.
        ENDIF.
    i resolved the error im gettin for table declaration but now d fm is not executing properly
    after execution it gives error message : Enter a Quantity.
    i dont knw frm whr it is coming.........im passin d values to table as:
        MOVE wa_ot_calc-pernr TO P2010-pernr.
        MOVE '1006' TO P2010-subty.
        MOVE wa_ot_calc-zotdate TO P2010-endda.
        MOVE wa_ot_calc-zotdate TO P2010-begda.
        MOVE sy-datum TO P2010-aedtm.
        MOVE sy-uname TO P2010-uname.
        MOVE wa_ot_calc-not_hrs TO P2010-stdaz.
        MOVE '1006' TO P2010-lgart.
    is anythin wrong in this..?

Maybe you are looking for

  • Change local currency to document in a query

    Hi I have a request from a user to see one of the query which displays purchase price differences currently in local currency, but user wants to be based on document currency. Can you help me out with the procedure to do so? I havent done such thing

  • Controling the 'name' of a file download

    function openPDFWordTwo(thisObj,pdfURL){ //For Opening Word formTitleId = thisObj.id.substr(0,thisObj.id.lastIndexOf(':')) + ":hiddenFormTitle"; formTitle = document.getElementById(formTitleId).value; window.location = pdfURL;    return false;Here is

  • Cs6 in cc 2014

    CC 2014: After installing CS6 from CC apps, (older version) I can only seem to get to Encore. I thought we were supposed to be able to use CS6??? Help! Thanks.

  • Where to configure the variable $baseurl in oim?

    Hi all, I am using the notification template located in OIM user and administrative console -> Advance -> System .. and there, there is a template that uses the $baseUrl variable. All is fine until want to send the notification, because when the noti

  • TS1424 I have purchased a iBook that has chapters missing. How do I get the whole book downloaded?

    I paid for an iTunes book and several chapters are missing from the download. Is there a way to get the missing chapters?