If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > Mutli User Invoicing System

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-26-11, 11:49
jx12345 jx12345 is offline
Registered User
 
Join Date: Apr 2010
Posts: 51
Mutli User Invoicing System

I'm working on an invoicing system that has to allow mutliple users ie... the system can be used by several different unrelated companies to produce their invoices.


One think i'm unsure about is the best way to create some of the primary keys:

For example

On a single user system an invoice would have a natural primary key of its invoice number, however, on the mutli-user system this is obviously not the case as two users(companies) may well have the same invoice number.

My first thought was to have a primary key made up of the two fields user_id & invoice number

Then i thought i might be better to have an internal invoice id as a primary key (autonumber, i'm using mysql) and then add a unique index to the user_id & invoice_no to prevent an individual user creating two invoices with the same number...

The idea of having a primary key made up of two fields always seems to be a bit of a hassle even though i think it makes more sense logically...

I wondered if anyone had any thoughts/comments on the two approaches..

many thanks

j
Reply With Quote
  #2 (permalink)  
Old 08-26-11, 14:20
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
I'm in favor of using the surrogate key (autonumber) as the primary key, and the combination of either company and invoice or the combination of user and invoice for the unique constraint.

I try to always have a PK that is used solely by and for my system. The database, app server, web server, etc. use my PK. The user never even sees the PK if I can help it, and they are NEVER allowed to change it.

-PatP
__________________
In theory, theory and practice are identical. In practice, theory and practice are unrelated.
Reply With Quote
  #3 (permalink)  
Old 08-27-11, 05:50
jx12345 jx12345 is offline
Registered User
 
Join Date: Apr 2010
Posts: 51
yes, that sounds like good sense to me...

thanks for the reply
Reply With Quote
  #4 (permalink)  
Old 08-27-11, 10:28
jx12345 jx12345 is offline
Registered User
 
Join Date: Apr 2010
Posts: 51
Another approach might be to create an entire set of new tables for each user.

Any thoughts/comments?
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On