-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from JustinFrizzell/purge-customer-data
Purge customer data
- Loading branch information
Showing
5 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
-- Requirement: usp_PurgeCustomerData | ||
|
||
-- We need a stored procedure that: Deletes personal data of the customer from relevant tables. | ||
|
||
-- Technical Requirements: | ||
-- Create a stored procedure named usp_PurgeCustomerData which: | ||
-- Takes a parameter named @CustomerID. | ||
-- Deletes or anonymizes data for the given customer across the database. | ||
|
||
-- Solution: WideWorldImporters\Challenges\StoredProcedures\usp_PurgeCustomerData.sql | ||
|
||
EXEC Challenges.usp_PurgeCustomerData @CustomerID = 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
WideWorldImporters/Challenges/Functions/ufn_DaysSinceLastInvoice.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
WideWorldImporters/Challenges/StoredProcedures/usp_PurgeCustomerData.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
CREATE PROCEDURE Challenges.usp_PurgeCustomerData | ||
@CustomerID INT | ||
AS | ||
BEGIN | ||
BEGIN TRANSACTION; | ||
BEGIN TRY | ||
|
||
-- Anonymise data in the Orders table | ||
UPDATE Sales.Orders | ||
SET | ||
Comments = NULL | ||
, DeliveryInstructions = NULL | ||
WHERE CustomerID = @CustomerID; | ||
|
||
-- Delete personal data from the Customers table | ||
DELETE FROM Sales.Customers | ||
WHERE CustomerID = @CustomerID; | ||
|
||
COMMIT TRANSACTION; | ||
|
||
END TRY | ||
BEGIN CATCH | ||
-- Rollback if there's an error | ||
ROLLBACK TRANSACTION; | ||
THROW; | ||
END CATCH | ||
END |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.