Results 1 to 2 of 2
  1. #1
    cshannon is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Feb 2014
    Posts
    2

    Update, Delete and Insert Help

    I have an assignment in Access SQL on Updates, Deletes and Inserts. I need help on a few problems, I will write the problem below and explain how I need help.


    Premiere has decided to no longer sell gas ranges, so they need to be removed from inventory. ALL orders for gas ranges must be removed also. However, if an order has other items on it, ONLY remove the order for the gas range. Modify the database.

    So I have an Orders table, which lists OrderNumber, OrderDate, and CustomerNumber. I also have an OrderLine table, which lists OrderNumber, PartNumber, Number Ordered, and Total Price. I need to do this with one Delete statement, but not sure how to delete from two tables, especially when the query needs to delete gas ranges from orders that have other parts on them.



    Another question:
    All Season has just placed an order for 10 cordless drills, for a price of $115.00. Use 21624 for the order number and the current date for their order date. Modify the database.
    So again, it seems like I need to insert different record types into different tables. I need to insert the order information into the Orders table (OrderNum, OrderDate) and also insert the OrderNum, PartNum, NumOrdered, and Price into the OrderLine table.

    Thanks for any help, I'm really stuck here

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    "Modify the database" to me means design changes. What you describe is just data management. Ideally, instead of running action SQLs, this data management would be done through forms.

    A rather bizarre exercise. Deleting ALL orders for gas ranges would be impractical because that would distort historical data. What should really happen is to deactivate the product in the inventory table and cancel all UNFULFILLED orders for gas ranges. But teachers come up all kinds of weird stuff just to demonstrate something.

    A single delete action will work only if tables have an established relationship and cascade delete is active. I don't see how one DELETE action is possible if you want to delete orders that are only for ranges as well as ranges from multi-item orders.

    Deleting from Orders table is a bit complicated. If cascade delete is in effect, this should also delete the associated gas range records from OrderLine table
    DELETE FROM Orders WHERE OrderNum IN (SELECT OrderNum FROM OrderLine WHERE PartNum=gas range part number AND Count(*)=1 GROUP BY OrderNum)

    Now delete the gas ranges records from other orders.
    DELETE FROM OrderLine WHERE PartNum = gas range part number

    Now delete from inventory.
    DELETE FROM Inventory WHERE somefield = 'gas range'

    The order INSERT would be two actions.

    INSERT INTO Orders(OrderNum, OrderDate, Customer) VALUES(21624, Date(), 'All Season')

    INSERT INTO OrderLine(OrderNum, PartNum, NumOrdered, Price) VALUES(21624, some part number, 10, 115)
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. delete insert
    By slimjen in forum Queries
    Replies: 5
    Last Post: 10-11-2013, 05:14 AM
  2. UPDATE and INSERT
    By csako1 in forum Access
    Replies: 3
    Last Post: 01-05-2012, 06:37 PM
  3. if exists UPDATE else INSERT
    By lloyddobler in forum Programming
    Replies: 18
    Last Post: 01-04-2012, 11:35 PM
  4. update vs. delete / insert
    By markjkubicki in forum Programming
    Replies: 1
    Last Post: 09-23-2010, 07:44 AM
  5. Insert & then Delete
    By surajparmar in forum Queries
    Replies: 2
    Last Post: 08-10-2010, 06:32 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums