Postgresql – Need the name value of the enterprise to be the same as it was when it was registered and not the value it currently has

database-designpostgresql

I will explain the problem with an example: I am designing a specific case of referential integrity in a table. In the logical design there are two tables, enterprise and document. We register the companies and then someone inserts the documents associated with it. The name of the enterprise is variable.

When it comes to recovering the documents, I need the name value of an enterprise to be the same as it was when it was registered and not the value it currently has.

The solution that I thought was to register the company again in each change with the same code, the updated name in this way would have the expected result, but I am not sure if it is the best solution. Can someone make a suggestion?
enter image description here

Best Answer

I'd simply store the register_name (meaning the first value that was taken by the name of the enterprise) in the enterprise table :

  • identerprise
  • code
  • name
  • register_name

Then I think you shouldn't use varchar(n) to store your text value (see that documentation page)