I’m trying to put together a database in SQL Server Management Studio 2008 which will manage the data without having to programatically process the data but I’m having some issues at the moment.
I have a main table called person, this table holds core data about a person and this is linked to a second table called customer in which they are included if they wish to have transaction permissions. Once a transaction has taken place the customer ID is placed into the transaction table.
|Person| |Customer| |Transaction|
|------| |--------| |-----------|
| ID |-\ | ID |-\ | ID |
| | \| person | \| Customer |
| | | | | |
Of the two links, the ID’s are PK’s and the secondary items (person/customer) are FK’s.
The problem I am having with this arrangement lies in the requirement that a person has to be kept if they have made a transaction and thus their customer ID appears in the transaction table.
I am not 100% sure on what approach to take, would a ‘Delete Rule – Cascade’ between person-customer with a ‘Delete Rule – No Action’ between Customer – Transaction create the desired effect?
Any thoughts approach or a better approach would be very much appreciated on this issue.
I think, yes, an
clause in
Customer.Personforeign key, and anclause in
Transaction.Customerforeign key would have the desired effect.Then any attemp to delete a Person, will delete the related Customer row, unless there are related Transcations. That will raise an error and the DELETE would be rolled back.