Quantcast
Viewing all articles
Browse latest Browse all 60

Want to Set Relationship Between 3 Tables (1st Child Table column value depends between two another table columns)

I am using Visual Basic with a Microsoft SQL Server Database for my WinForms Application.

I have 3 Tables - Purchases, Sales, Transactions (for payment/receipt)

In the Transactions table, I am using Purchase Table's RowId OR Sales Table's RowId as a reference to determine the payment belongs to which purchase/sale record.

Now after entering records in Transaction table, I don't want to let Delete Purchase/Sale entry if there RowId is used in Transactions table records.

What I have tried is RowIds of both Purchase & Sale Tables are Unique values so created 1 view named PurchaseSaleIds which Unions values of both table, now I have PurchaseSaleIds as Primary Key Table (View) & Transactions as Foreign Key Table, however it is not allowed in SQL Server to set foreign key relation between View & Table.

Table Purchases have BillID primary key column, Table Invoices have InvID primary key column and under Transaction table I have AgainstBillId Column which will store ID number between BillID Or InvID.


Viewing all articles
Browse latest Browse all 60

Trending Articles