{"id":10096,"date":"2023-06-18T08:05:45","date_gmt":"2023-06-17T23:05:45","guid":{"rendered":"https:\/\/www.sambuichi.jp\/?p=10096"},"modified":"2023-06-23T09:13:03","modified_gmt":"2023-06-23T00:13:03","slug":"shifting-towards-simplicity-using-single-unique-identifiers-in-our-data-model","status":"publish","type":"post","link":"https:\/\/www.sambuichi.jp\/?p=10096","title":{"rendered":"Shifting Towards Simplicity: Using Single Unique Identifiers in Our Data Model"},"content":{"rendered":"<p>Views: 25<\/p><div id=\"header\">\n<h1>Shifting Towards Simplicity: Using Single Unique Identifiers in Our Data Model<\/h1>\n<\/div>\n<div id=\"content_adoc\">\n<div id=\"preamble\">\n<div class=\"sectionbody\">\n<div class=\"paragraph data-line-5\">\n<p>Nobuyuki SAMBUICHI<\/p>\n<\/div>\n<div class=\"paragraph data-line-7\">\n<p><a href=\"https:\/\/www.iso.org\/committee\/5648297.html\" data-href=\"https:\/\/www.iso.org\/committee\/5648297.html\">ISO\/TC295 Audit data services<\/a>\/SG1 Semantic model Convener<\/p>\n<\/div>\n<div class=\"paragraph data-line-9\">\n<p>In our current table and field definitions, we have several tables that define their primary key as a combination of multiple fields. I recommend that we use a single primary key to define our object classes from our table definition. Primary keys and referenced identifiers (foreign keys) should be defined more simply and clearly in UML associations.<\/p>\n<\/div>\n<div class=\"paragraph data-line-12\">\n<div class=\"title\">User<\/div>\n<p>Provide some pros and cons of defining a primary key on multiple fields.<\/p>\n<\/div>\n<div class=\"paragraph data-line-14\">\n<p>Provide the advantage of designing the semantic model of object classes using a single unique identifier (primary key) attribute.<\/p>\n<\/div>\n<div class=\"paragraph data-line-16\">\n<p>Convince non-technical experts to change the table definition to an object class definition with a single unique identifier.<\/p>\n<\/div>\n<div class=\"paragraph data-line-19\">\n<div class=\"title\">ChatGPT<\/div>\n<p>Sure, let&#8217;s break down your questions one by one.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"sect1 data-line-21\">\n<h2 id=\"_pros_and_cons_of_defining_a_primary_key_on_multiple_fields_composite_key\">Pros and Cons of defining a Primary Key on Multiple Fields (Composite Key):<\/h2>\n<div class=\"sectionbody\">\n<div class=\"sect2 data-line-23\">\n<h3 id=\"_pros\">Pros:<\/h3>\n<div class=\"ulist data-line-25\">\n<ul>\n<li class=\"data-line-25\">\n<p><strong>Natural Data Relationships:<\/strong><br \/>\nComposite keys can naturally represent data relationships, such as a student taking multiple courses. A composite key of student ID and course ID can uniquely represent each course taken by each student.<\/p>\n<\/li>\n<li class=\"data-line-28\">\n<p><strong>Data Integrity:<\/strong><br \/>\nComposite keys can help enforce data integrity at a granular level, as the combination of fields must be unique.<\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<div class=\"sect2 data-line-31\">\n<h3 id=\"_cons\">Cons:<\/h3>\n<div class=\"ulist data-line-33\">\n<ul>\n<li class=\"data-line-33\">\n<p><strong>Complexity:<\/strong><br \/>\nComposite keys can make queries more complex. You have to specify all parts of the key in the WHERE clause of a query, making SQL harder to write and read.<br \/>\nJoin Operations: Using composite keys can make join operations more complex, as you need to join on all parts of the key.<\/p>\n<\/li>\n<li class=\"data-line-37\">\n<p><strong>ORM Complications:<\/strong><br \/>\nObject-Relational Mapping (ORM) frameworks often have difficulties working with composite keys, as they are harder to map to objects than single-value keys.<\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"sect1 data-line-40\">\n<h2 id=\"_advantages_of_designing_semantic_model_of_object_classes_using_a_single_unique_identifier_primary_key_attribute\">Advantages of Designing Semantic Model of Object Classes Using a Single Unique Identifier (Primary Key) Attribute:<\/h2>\n<div class=\"sectionbody\">\n<div class=\"ulist data-line-42\">\n<ul>\n<li class=\"data-line-42\">\n<p><strong>Simplicity:<\/strong><br \/>\nA single unique identifier makes it easier to reference a specific instance of an object, simplifying SQL queries, updates, and deletes.<\/p>\n<\/li>\n<li class=\"data-line-45\">\n<p><strong>ORM Compatibility:<\/strong><br \/>\nORM frameworks generally work best with single-value keys. A single unique identifier aligns well with object-oriented programming principles, where each object typically has a single unique identifier.<\/p>\n<\/li>\n<li class=\"data-line-48\">\n<p><strong>Scalability:<\/strong><br \/>\nSingle-value keys can make it easier to distribute data across multiple nodes in a distributed database, as each object can be easily hashed to a specific node.<\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"sect1 data-line-51\">\n<h2 id=\"_guiding_non_technical_colleagues_towards_the_adoption_of_a_single_unique_identifier_in_object_class_definition\">Guiding Non-Technical Colleagues Towards the Adoption of a Single Unique Identifier in Object Class Definition<\/h2>\n<div class=\"sectionbody\">\n<div class=\"paragraph data-line-52\">\n<p>Now, in order to guide non-technical colleagues towards the adoption of an object class definition with a single unique identifier, you might consider highlighting the following points:<\/p>\n<\/div>\n<div class=\"ulist data-line-54\">\n<ul>\n<li class=\"data-line-54\">\n<p><strong>Simplification of Data Access:<\/strong><br \/>\nA single unique identifier allows for easier data access, reducing complexity in both coding and understanding how data is connected. It&#8217;s akin to having a unique ID for every book in a library, making it easier to find and catalog each item.<\/p>\n<\/li>\n<li class=\"data-line-57\">\n<p><strong>Performance:<\/strong><br \/>\nDatabases perform better when searching, sorting, or joining on single-value keys, making our applications faster and more responsive.<\/p>\n<\/li>\n<li class=\"data-line-60\">\n<p><strong>Future Proofing:<\/strong><br \/>\nModern coding practices and ORM tools are designed to work optimally with single-value keys. By adopting this practice, we future-proof our system, making it easier to update or switch to new tools in the future.<\/p>\n<\/li>\n<li class=\"data-line-63\">\n<p><strong>Data Consistency:<\/strong><br \/>\nUsing a single unique identifier can help prevent duplicate records and improve the consistency of our data, which helps ensure the information we&#8217;re working with is accurate and reliable.<br \/>\nRemember, it&#8217;s all about making data easier to work with and understand, both for us and for the computer systems we&#8217;re using.<\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"sect1 data-line-67\">\n<h2 id=\"_example_base_module_accounting_period\">Example: Base module Accounting Period<\/h2>\n<div class=\"sectionbody\">\n<div class=\"paragraph data-line-69\">\n<div class=\"title\">User<\/div>\n<p>Provides an example scenario where changing to a single unique identifier is better than combining multiple fields. And provide reasons why this change is important with sample use case.<\/p>\n<\/div>\n<div class=\"paragraph data-line-71\">\n<p>For accounting data, the entry should report period for this record.<br \/>\nCurrent period table is defines a primary key with combination of Fiacal Year and  Accounting Period.<\/p>\n<\/div>\n<div class=\"paragraph data-line-74\">\n<p>Folllowing is the current definition. Provide your updated object class with single unique identifier.<\/p>\n<\/div>\n<table class=\"tableblock frame-all grid-all stretch data-line-76\">\n<colgroup>\n<col style=\"width: 7.1428%;\">\n<col style=\"width: 28.5714%;\">\n<col style=\"width: 14.2857%;\">\n<col style=\"width: 50.0001%;\">\n<\/colgroup>\n<tbody>\n<tr>\n<td class=\"tableblock halign-center valign-top\">\n<p class=\"tableblock\">No.<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">Name<\/p>\n<\/td>\n<td class=\"tableblock halign-center valign-top\">\n<p class=\"tableblock\">Datatype<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">Description<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"tableblock halign-center valign-top\">\n<p class=\"tableblock\">1<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">Fiscal Year<\/p>\n<\/td>\n<td class=\"tableblock halign-center valign-top\">\n<p class=\"tableblock\">String<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">The fiscal year in which the calendar date occurs. The year shall be shown in four digits as \u201cYYYY\u201d, which is part of the extended format and the \u201cYYYYMM-DD\u201d in ISO 8601-1.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"tableblock halign-center valign-top\">\n<p class=\"tableblock\">2<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">Accounting Period<\/p>\n<\/td>\n<td class=\"tableblock halign-center valign-top\">\n<p class=\"tableblock\">String<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">The accounting period in which the calendar date occurs. EXAMPLE W1\u2013W53 for weekly periods, M1\u2013M12 for monthly periods, Q1\u2013Q4 for quarterly periods, and from any beginning date to any ending date.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"tableblock halign-center valign-top\">\n<p class=\"tableblock\">3<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">Accounting Period Beginning Date<\/p>\n<\/td>\n<td class=\"tableblock halign-center valign-top\">\n<p class=\"tableblock\">Date<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">The calendar beginning date of the current accounting period.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"tableblock halign-center valign-top\">\n<p class=\"tableblock\">4<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">Accounting Period Ending Date<\/p>\n<\/td>\n<td class=\"tableblock halign-center valign-top\">\n<p class=\"tableblock\">Date<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">The calendar ending date of the current accounting period.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"paragraph data-line-104\">\n<div class=\"title\">ChatGPT<\/div>\n<p>Absolutely, let&#8217;s start by understanding the scenario. It appears we&#8217;re currently using a combination of &#8220;Fiscal Year&#8221; and &#8220;Accounting Period&#8221; as a composite primary key. While it does work in most scenarios, it might create unnecessary complications in the system.<\/p>\n<\/div>\n<div class=\"paragraph data-line-106\">\n<p>An example of a problem that can arise due to this composite key setup is when the data needs to be referenced elsewhere. For example, if we need to link an accounting transaction to a specific accounting period, we would have to include both the &#8220;Fiscal Year&#8221; and &#8220;Accounting Period&#8221; in the transaction record. This can become cumbersome and increase the risk of data inconsistencies.<\/p>\n<\/div>\n<div class=\"paragraph data-line-108\">\n<p>To solve this, we can create a single, unique identifier for each accounting period. This unique identifier, or primary key, can then be used to link to the accounting period from other tables.<\/p>\n<\/div>\n<div class=\"paragraph data-line-110\">\n<p>Here is a modified version of the object class for your consideration:<\/p>\n<\/div>\n<table class=\"tableblock frame-all grid-all stretch data-line-112\">\n<colgroup>\n<col style=\"width: 7.1428%;\">\n<col style=\"width: 28.5714%;\">\n<col style=\"width: 14.2857%;\">\n<col style=\"width: 50.0001%;\">\n<\/colgroup>\n<tbody>\n<tr>\n<td class=\"tableblock halign-center valign-top\">\n<p class=\"tableblock\">No.<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">Name<\/p>\n<\/td>\n<td class=\"tableblock halign-center valign-top\">\n<p class=\"tableblock\">Datatype<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">Description<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"tableblock halign-center valign-top\">\n<p class=\"tableblock\">1<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">Period ID<\/p>\n<\/td>\n<td class=\"tableblock halign-center valign-top\">\n<p class=\"tableblock\">String<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">A unique identifier for the accounting period, which combines fiscal year and accounting period in a single attribute. Format: &#8220;YYYYMM&#8221; for monthly periods, &#8220;YYYYQX&#8221; for quarterly periods, &#8220;YYYYWX&#8221; for weekly periods.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"tableblock halign-center valign-top\">\n<p class=\"tableblock\">2<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">Fiscal Year<\/p>\n<\/td>\n<td class=\"tableblock halign-center valign-top\">\n<p class=\"tableblock\">String<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">The fiscal year in which the calendar date occurs. The year shall be shown in four digits as \u201cYYYY\u201d, which is part of the extended format and the \u201cYYYYMM-DD\u201d in ISO 8601-1.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"tableblock halign-center valign-top\">\n<p class=\"tableblock\">3<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">Accounting Period<\/p>\n<\/td>\n<td class=\"tableblock halign-center valign-top\">\n<p class=\"tableblock\">String<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">The accounting period in which the calendar date occurs. EXAMPLE W1\u2013W53 for weekly periods, M1\u2013M12 for monthly periods, Q1\u2013Q4 for quarterly periods, and from any beginning date to any ending date.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"tableblock halign-center valign-top\">\n<p class=\"tableblock\">4<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">Accounting Period Beginning Date<\/p>\n<\/td>\n<td class=\"tableblock halign-center valign-top\">\n<p class=\"tableblock\">Date<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">The calendar beginning date of the current accounting period.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"tableblock halign-center valign-top\">\n<p class=\"tableblock\">5<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">Accounting Period Ending Date<\/p>\n<\/td>\n<td class=\"tableblock halign-center valign-top\">\n<p class=\"tableblock\">Date<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">The calendar ending date of the current accounting period.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"paragraph data-line-144\">\n<p>The benefit of making this change is evident when we consider the scenario of reporting an accounting transaction. Instead of having to report two different pieces of information (Fiscal Year and Accounting Period), we now only need to report the &#8220;Period_ID&#8221;. This makes the data easier to work with, improves data integrity, and simplifies our database and object model.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"footer\">\n<div id=\"footer-text\">\nLast updated 2023-06-19 12:30:25 +0900\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Views: 25 Shifting Towards Simplicity: Using Single Unique Identifiers in Our Data Model Nobuyuki SAMBUICHI IS [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":10097,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[71,69,30],"tags":[],"_links":{"self":[{"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=\/wp\/v2\/posts\/10096"}],"collection":[{"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10096"}],"version-history":[{"count":11,"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=\/wp\/v2\/posts\/10096\/revisions"}],"predecessor-version":[{"id":10182,"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=\/wp\/v2\/posts\/10096\/revisions\/10182"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=\/wp\/v2\/media\/10097"}],"wp:attachment":[{"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10096"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10096"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10096"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}