I need some guidance on designing the schema for invoices in a multi-tenant application.
I have a table called EmployeePay
which holds all the information required to generate an invoice. The invoice table would have the invoice number, invoice created date and VAT
rate. I am thinking to create a Sequence
object for each Tenant
to generate an invoice number.
EmployeePay Table: EmployeeID, Hours, Rate, InvoiceID (FK)
Invoice Table: InvoiceID (PK) (Identity), InvoiceNumber, InvoiceDate, VATRate, TenantID
Is it okay to have hundreds of Sequence objects in a database, as I’ll have to create one for each tenant? I’ll also have to create same amount of stored procedures which returns the next invoice number (I prefer a separate stored procedure for each tenant rather than having one large stored procedure with hundreds of choices in a select case statement).
Another concern is, is it theoretical to insert into the master table (Invoice
) based on the transaction table (EmployeePay
) and then use its primary key(InvoiceID
) to update the transaction table?
Thanks in advance.