I made several projects (CMS and EC system) that required some data to be versioned.
I usually come with such a scheme
+--------------+ + foobar + +--------------+ + foobar_id + + version + +--------------+
it worked fine, but I wonder if there is a way to make this better. The main problem with this solution: you should always use a subquery to get the latest version.
ie:
SELECT * FROM foobar WHERE foobar_id = 2 and version = (SELECT MAX(version) FROM foobar f2 WHERE f2 = 2)
This makes most queries more complex and also has some performance flaws.
So, it would be nice if you shared your experience with creating a table with a version and what kind and minuses of each method.
thanks
. foobar_history - FK foobar_id. . , , , , 99% , .
, , _history .
, , , . , foobar, foobar_History foobar, History , . , , , .
, , , . , . , , where.
Pro:
:
, .
. , . . , . ( ), , .
? , db, . , . , ( + ). - , , . , , .
. , : ,
, , . , .
version_status /. , , -() , - name + pin, () .
version_status
name + pin
TABLE foobar(foobar_id PK, business_key, version, version_status, .....) SELECT * FROM foobar WHERE business_key = 'myFoobar3' AND version_status = 'current'
- - , foobar_id . , ? , , , . , , .
foobar_id
Oracle,
* from ( .* , row_number() over ( foobar_id desc) rn foobar a WHERE foobar_id = 2 ), rn = 1
, , .
- , , , . , current_row , , .
, , , , . , , .
If you are in the world of reporting, then there are many other options that I will not indicate here. Details can be found in data warehouse data modeling books.
Source: https://habr.com/ru/post/1724902/More articles:How to import data into a relational database in RDF? - relational-databaseКак создать пусковую установку отладки Eclipse, которая запускает класс - javaHow can I implement scripts in my game? - c ++Open files from current directory using C ++ wildcard - c ++Serializing an Object List Using Protobuf-net - c #Static testing for Scala - scalahttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1724904/interceptlog-all-database-calls-to-sql-server-from-a-net-assembly&usg=ALkJrhjzRhkVaNHQVAvmVJm-12IPJhhg5QIs UnregisterHotKey () important to clean up? - c ++Fluent NHibernate: how to say this so as not to display the base class - c #Alternative to STR_TO_DATE () in sqlite - sqliteAll Articles