Last post May 25, 2020 02:40 PM by mgebhard
May 25, 2020 02:24 PM|msdevm|LINK
Has any one done a trigger that do not allow the app user or via the query analyser to delete a record once such record id is linked to another data table.
I have POS with the following tables
Table->Customers data with Primary indexed key on the indentity int column [CustomerId]
Table->Orders data with Primary indexed key on the indentity int column [OrderId] ->Contains column Customers->CustomerId
Table->Payments data with Primary indexed key on the indentity int column [PaymentId] -> Contains relation to column orders->OrderId
I understand that by setting Foreign Key this would be possible but it is too late now because the way the tables were setup.
That is why I am trying to set up a trigger in the customer data table that do not allow to delete such customer if customer data is linked to an order and payment data.
The same way goes for the payment table data if payment applied is linked to an order or customer data do not allow to delete such payment.
Please provide sample
May 25, 2020 02:40 PM|mgebhard|LINK
Referential integrity should handle this without needing a trigger since the Order table has a foreign key constraint to to the Customer table.
You can delete a payment though. Do not allow deletes on the Payment table if you do not want to allow deletes.