Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am working on a new project. The domain logic of the project is as follows:

A user uploads a file (Document) and gives a title, then another user comes along and (s)he also tries to upload a file with the same title. This is OK providing that the body of the document has differences.

How can I design my domain model so that my web application that will later consume the data can inform the user viewing a particular document "hey there is another version of this document".

Here is a simple ERD of what I have, but that obviously does not perform what I want above.

enter image description here

I would greatly appreciate any help and advice.


share|improve this question
up vote 4 down vote accepted

You could keep them all in the same table, simply with a column to track version numbers:

  id (part of PK)
  version_number (part of PK)
  creator_id (FK to
  version_date (the date that this version is created - not necessary, but good to have)

Your application will need to be capable of handling updating the version number of a document when a new record is added but it is a new version of an existing document. You also need to ensure that any document metadata (such as Title) changes are propagated to all related documents. You could do this by allowing document ID to not be unique, and the primary key is a combination of document ID and version number. Otherwise, it could be impossible to tell which record to update.

Another way would be to have a stub for document metadata and a separate table for all versions:

  id (PK)
  creator (FK to
  (other metadata)

  id (PK)
  document_id (FK to
  (other fields)

The second option is a slightly more complicated structure, but will give you better referential integrity because all version must be linked to a document stub by a foreign key.

Personally, I'd go with the second version.

share|improve this answer
I'd actually recommend the first version, as it allows for a document's title and creator/owner to change. Consider an IsCurrent bit field, it makes querying simpler. – Jon of All Trades Sep 13 '13 at 23:01
You can enter another version with increased version_number, but smaller version_date. Would you want to prevent this? – A-K Sep 22 '13 at 3:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.