I have a SalesTransaction
and an Invoice
table:
Create Table SalesTransaction
(
SalesTransactionId int Identity(1,1) Primary Key,
CustomerId int Foreign key references Customer(CustomerId) ,
ProductId int Foreign key references Product(ProductID),
Price money,
Quantity int,
Total money,
InvoiceId int
)
and
Create Table Invoice
(
InvoiceId int Primary Key,
InvoiceAmount money Not Null ,
BalanceAmount money,
AmountPaid money Not Null
)
What I want is the Invoiceid
from Invoice
table to tag InvoiceId
of SalesTransaction
table.
At first the InvoiceId
of SalesTransaction
is NULL, and after the data for invoice table s added, it should tag back to InvoiceId
of SalesTransaction
table
First solution (with only a new Foreign Key)
For the following schema
Here are your INSERT/UPDATE queries
I would also suggest you to set the column
InvoiceId
of tableInvoice
as an Identity.Second solution (with a new foreign key and an identity for invoice pk)
For the following schema
Here are your INSERT/UPDATE queries