Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8049223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:43:48+00:00 2026-06-05T06:43:48+00:00

I do not want the orders to be deleted when a customer is deleted.

  • 0
  • I do not want the orders to be deleted when a customer is deleted. (On Delete Cascade)
  • I use identity columns so I do not need On Update Cascade
  • It should be possible to delete a customer table although there exist orders pointing/referencing to a customer. I do not care when the customer is gone because I still need the order table for other tables.

Does a foreign key make sense in this scenario when I do not use Referential Integrity with On Delete/Update Cascade ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T06:43:49+00:00Added an answer on June 5, 2026 at 6:43 am

    Yes. The foreign key is not in place only to clean up after yourself but primarily to make sure the data is right in the first place (it can also assist the optimizer in some cases). I use foreign keys all over the place but I have yet to find a need to implement on cascade actions. I do understand the purpose of cascade but I’ve always found it better to control those processes myself.

    EDIT even though I tried to explain already that you can work around the cascade issue (thus still satisfying your third condition), I thought I would add an illustration:

    You can certainly still allow for orders to remain after you’ve deleted a customer. The key is to make the Orders.CustomerID column nullable, e.g.

    CREATE TABLE dbo.Customers(CustomerID INT PRIMARY KEY);
    
    CREATE TABLE dbo.Orders(OrderID INT PRIMARY KEY, CustomerID INT NULL
        FOREIGN KEY REFERENCES dbo.Customers(CustomerID));
    

    Now when you want to delete a customer, assuming you control these operations via a stored procedure, you can do it this way, first setting their Orders.CustomerID to NULL:

    CREATE PROCEDURE dbo.Customer_Delete
      @CustomerID INT
    AS
    BEGIN
      SET NOCOUNT ON;
    
      UPDATE dbo.Orders SET CustomerID = NULL
        WHERE CustomerID = @CustomerID;
    
      DELETE dbo.Customers
        WHERE CustomerID = @CustomerID;
    END
    GO
    

    If you can’t control ad hoc deletes from the Customers table, then you can still achieve this with an instead of trigger:

    CREATE TRIGGER dbo.Cascade_CustomerDelete
    ON dbo.Customers
    INSTEAD OF DELETE
    AS
    BEGIN
      SET NOCOUNT ON;
    
      UPDATE o SET CustomerID = NULL
        FROM dbo.Orders AS o
        INNER JOIN deleted AS d
        ON o.CustomerID = d.CustomerID;
    
      DELETE c
        FROM dbo.Customers AS c
        INNER JOIN deleted AS d
        ON c.CustomerID = d.CustomerID;
    END
    GO
    

    That all said, I’m not sure I understand the purpose of deleting a customer and keeping their orders (or any indication at all about who placed that order).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I do not want to use .htaccess. How should I change my Directory attributes?
customers does not want to allow user to use back or forward button. Just
The problem We have a table of duplicate customer numbers: A varchar(16) NOT NULL,
I want to change order in plist file not programmatically but from xcode. Is
Problem: I want to list n number of games from each genre (order not
Type.GetFields() does not return fields in a particular order, but I want to sort
I do not want to change the public static void ... String[] args part
I do not want my clients to select a parent page from the drop
My client does not want to have ftp on the production box (understandable). We
The following code does not want to compile. See the included error message. Code:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.