Results 1 to 5 of 5

Thread: How can I delete a record in a database without deleting it's related records?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2011
    Posts
    67

    How can I delete a record in a database without deleting it's related records?

    I have a customer table and an order table and I want to give the user the option to delete a customer from the database without deleting that customer's orders as deleting the orders would mess up the statistics.

    Each record in the order table has a field containing the customer number of the customer who made the order.

    When trying to delete a customer from the customer table, I get the error "The record cannot be deleted or changed because table 'tblOrder' includes related records."

    How can I delete the customer without deleting their orders?

    I am using VB.NET in VS 2010

    Thanks

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: How can I delete a record in a database without deleting it's related records?

    You don't. You could add a Status value indicating that the Customer is not active but frankly I don't see the need to do anything at all.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 2011
    Posts
    67

    Re: How can I delete a record in a database without deleting it's related records?

    "I don't see the need to do anything at all."
    I was thinking of doing it as if a customer wanted to close their account, they would probably expect their information to be deleted.

    It's not necessary though I just though it would be a nice idea, thanks for the reply.

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: How can I delete a record in a database without deleting it's related records?

    Actually I would counsel against deleting the information in this situation even if you were still using good old paper files. Deleted records have a habit of arising to bite you in the backside a few years down the track.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  5. #5
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: How can I delete a record in a database without deleting it's related records?

    Having a status that says a customer is inactive is standard in most financial packages I've worked with.

    Deleting the customer row and leaving the "activity" - thus having no idea what the "name" associated with that activity would be - is really a bad idea. Very much against standard practice.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

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
  •  



Click Here to Expand Forum to Full Width