Data management method based on relational database and related device
By introducing a logical deletion method with start and end time fields in a relational database, the problem of data lifecycle management is solved, the data management process is simplified, and query efficiency and targeting are improved.
Patent Information
- Application Number
- CN202310115917.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-08
- Publication Date
- 2026-02-03
- Estimated Expiration
- 2043-02-08
AI Technical Summary
The lack of existing technologies for restricting deletion operations and managing the data lifecycle in relational databases leads to complex and inefficient data management.
By introducing start and end time fields into the primary key of the data table to represent the start and end of the data lifecycle, logical deletion can be performed using the end time field instead of actual deletion. By establishing a relational primary key, a relational database can be formed, thus realizing data lifecycle management.
It enables logical deletion of data, reduces physical deletion operations, simplifies data management processes, and improves data query efficiency and the targeted nature of lifecycle management.
Smart Images

Figure CN116521669B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of database management, in particular to a data management method based on a relational database and related equipment. BACKGROUND
[0002] Data is important, but the amount of data generated by application systems is huge and the management requirements are high. In the field of relational database management, there is currently no research and technology that meets the business use and data life cycle management while limiting the delete operation. SUMMARY
[0003] To solve the problems in the above related technologies, the present application provides a data management method based on a relational database and related equipment. By setting the data table primary key to include a start time field and an end time field, the start time field and the end time field respectively represent the start and end of the data life cycle, and the end time field content is matched with the filtering condition, so that the data in the data table obtained by querying according to the filtering condition does not include data with content in the end time field. Logical deletion is performed on the data to replace physical deletion, which can be used for the case of limiting the delete operation.
[0004] The present application provides a data management method based on a relational database, which comprises:
[0005] Setting the primary key of the data table to include a start time field and an end time field;
[0006] Establishing a relationship between the associated primary keys of a plurality of data tables to form a relational database, wherein the associated primary keys are primary keys that do not include a start time field and an end time field;
[0007] Determining the time when data is entered into the data table and recording it in the corresponding start time field of the data;
[0008] Determining the time when the data needs to be deleted and recording it in the corresponding end time field of the data;
[0009] When a data query is needed, input a first target filtering condition to query the first target data in the data table,
[0010] The first target filtering condition includes a first condition, and the first condition is related to the end time field;
[0011] The first target data in the data table obtained by querying is sorted according to the start time field.
[0012] In some embodiments, when the time when data is entered into the data table is determined and recorded in the corresponding start time field, the end time field is blank; and the first condition is that the end time field is blank.
[0013] In some embodiments, the method further includes:
[0014] When you need to query historical data, enter the second target filter conditions to query the second target data in the data table. The second target filter conditions include conditions related to the primary key except for the end time field. The second target data in the queried data table is sorted by the start time field.
[0015] In some embodiments, the method further includes:
[0016] When data in a data table needs to be modified, follow these steps.
[0017] The first target data is obtained by performing the data novelty search.
[0018] Identify the data to be modified in the first target data set;
[0019] Once it is determined that the data to be modified needs to be deleted, the time when it is determined that the data to be modified needs to be deleted is recorded in the corresponding end time field;
[0020] Enter the modified data into the corresponding data table, determine the time when the modified data was entered into the data table, and record it in the start time field corresponding to the modified data.
[0021] In some embodiments, the data table does not include foreign keys.
[0022] This application also provides a data management device based on a relational database, including:
[0023] The settings module is used to set the primary key of the data table, including the start time and end time fields;
[0024] The database creation module establishes relationships between the primary keys of multiple data tables to form a relational database. The primary keys are those that do not include the start time and end time fields.
[0025] The first determination module is used to determine the time when the data is entered into the data table and record the corresponding start time field of the data.
[0026] The second determination module is used to determine the time when the data needs to be deleted and record it in the corresponding end time field of the data.
[0027] The query module is used to query the first target data in the data table when a data search is required. The first target filter condition includes a first condition, which is related to the end time field.
[0028] The display module is used to display the first target data in the data table obtained from the query. The first target data is sorted by the start time field.
[0029] This application also provides an electronic device, including:
[0030] The memory and processor, wherein the memory stores a computer program that, when executed by the processor, performs any of the data management methods based on a relational database as described above.
[0031] This application also provides a storage medium storing a computer program that can be executed by one or more processors and can be used to implement any of the above-mentioned data management methods based on a relational database.
[0032] This application provides a data management method and related equipment based on a relational database. It designs data tables based on conventional modeling methods, establishes relationships between data tables to form a database, and meets the needs of conventional business use.
[0033] By setting the primary key of the data table to include start and end time fields to represent the start and end of the data lifecycle, the problem of data lifecycle management is solved.
[0034] Matching the end time field content to the filter conditions ensures that the data retrieved from the table based on the filter conditions does not include data with content in the end time field. In other words, it only displays data whose lifecycle has not ended. Logical deletion of data is performed instead of actual deletion, which can be specifically applied to situations where deletion operations are restricted. Attached Figure Description
[0035] The present application will be described in more detail below based on embodiments and with reference to the accompanying drawings.
[0036] Figure 1 A schematic diagram illustrating the implementation process of a data management method based on a relational database, provided in an embodiment of this application;
[0037] Figure 2 This is a schematic diagram of the composition structure of an electronic device provided in an embodiment of this application.
[0038] In the accompanying drawings, the same parts are referred to by the same reference numerals, and the drawings are not drawn to scale. Detailed Implementation
[0039] To make the objectives, technical solutions, and advantages of this application clearer, the application will be further described in detail below with reference to the accompanying drawings. The described embodiments should not be regarded as limitations on this application. All other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0040] In the following description, references are made to “some embodiments,” which describe a subset of all possible embodiments. However, it is understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.
[0041] If the application documents contain similar descriptions such as "first, second, third", the following explanation shall be added: In the following description, the terms "first, second, third" are used only to distinguish similar objects and do not represent a specific order of objects. It is understood that "first, second, third" may be interchanged in a specific order or sequence where permitted, so that the embodiments of this application described herein can be implemented in an order other than that illustrated or described herein.
[0042] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application only and is not intended to limit this application.
[0043] To address the problems existing in related technologies, this application provides a data management method based on a relational database. This method is applied to electronic devices, such as servers, mobile terminals, computers, and cloud platforms. The data management functionality provided in this application, based on a relational database, can be implemented by the processor of the electronic device calling program code, which can be stored in a computer storage medium.
[0044] This application provides a data management method based on a relational database. Figure 1 This application provides a schematic diagram of the implementation process of a data management method based on a relational database, as illustrated in the embodiments below. Figure 1 As shown, it includes:
[0045] Step S101: Set the primary key of the data table to include start time and end time fields.
[0046] In this embodiment of the application, the primary key and other fields of the data table are designed in the usual modeling manner, and two additional fields, start time and end time, are added to form a composite primary key with other primary keys.
[0047] The start time represents the beginning of the data lifecycle, and the end time represents the end of the data lifecycle. Each piece of data has its corresponding start time field and end time field. Each piece of data can be divided differently according to the actual application requirements. In some embodiments, it can be divided into groups, segments, batches, or other different categories.
[0048] Step S102: Establish relationships between the primary keys of multiple data tables to form a relational database, wherein the primary key does not include the start time and end time fields.
[0049] In this embodiment of the application, the database is composed of data tables. When there are multiple data tables and table relationships are required, only the primary keys other than the start and end time fields need to be associated.
[0050] Step S103: Determine the time for data entry into the data table and record it in the corresponding start time field.
[0051] The start time represents the beginning of the data's lifecycle. The start time field records the time when the data was entered into the data table.
[0052] In some embodiments, when entering or inserting data into a data table, other processes may also be included, which may be adjusted according to the specific applicable project or database.
[0053] In some embodiments, the end time field is empty after the data is entered into the data table.
[0054] Step S104: Determine the time when the data needs to be deleted and record it in the corresponding end time field.
[0055] In this embodiment, the end time field can satisfy the database that restricts deletion operations. When it is determined that data needs to be deleted, the time when the deletion operation is determined is recorded in the end time field of the data, which means that the current data lifecycle has ended, and thus no deletion operation is performed.
[0056] In the above embodiment, the step of recording the time when the deletion operation needs to be performed into the end time field corresponding to the data is specifically set to update the content of the end time field to the time when the data needs to be deleted.
[0057] In this embodiment, since there is no data deletion operation and no foreign key is involved, foreign keys do not need to be set, thus reducing the database burden.
[0058] Step S105: When a data search is required, input the first target filter condition to query the first target data in the data table. The first target filter condition includes a first condition, which is related to the end time field.
[0059] In this embodiment of the application, the content of the first condition is the state description before the time when the end time field is recorded to determine that the data needs to be deleted. Because the end time field represents the end of the data life cycle, when a new data query is needed, data whose life cycle has ended needs to be filtered out so that the data whose life cycle has ended is not displayed in the query results, that is, the data that needs to be deleted is logically deleted.
[0060] In some embodiments, the content of the end time field includes two types: empty and the time when the data needs to be deleted. The first condition mentioned above is that the end time field is blank. From the perspective of data lifecycle, an empty end time field means that the data is the latest data.
[0061] Step S106: Sort the first target data in the retrieved data table by the start time field.
[0062] In some embodiments, the first target data is ordered or reversed according to the start time field.
[0063] Data modification includes deleting the data to be modified and entering the modified data. In this embodiment, data modification specifically includes entering the end time field content of the data to be modified and entering the modified data.
[0064] In some embodiments, when data needs to be modified, the following steps are performed.
[0065] The first target data is obtained by performing the data novelty search.
[0066] Identify the data to be modified in the first target data set;
[0067] Once it is determined that the data to be modified needs to be deleted, the time when it is determined that the data to be modified needs to be deleted is recorded in the corresponding end time field;
[0068] Enter the modified data into the corresponding data table, determine the time when the modified data was entered into the data table, and record it in the start time field corresponding to the modified data.
[0069] In this embodiment of the application, target data in the data table is queried by inputting target filter conditions. When the target filter conditions do not include conditions related to the end time field, the data that can be displayed includes data whose life cycle has ended.
[0070] In some embodiments, when a query of historical data is required, a second target filter condition is entered to query the second target data in the data table. The second target filter condition includes conditions related to the primary key except for the end time field, i.e., conditions related to the end time field are excluded. The second target data in the queried data table is sorted by the start time field.
[0071] In the above embodiments, sorting the second target data by the start time field can sequentially display the complete record history of the second target data in the data table.
[0072] Based on the foregoing embodiments, this application provides an electronic device. Figure 2 This is a schematic diagram of the composition structure of the electronic device provided in the embodiments of this application, such as... Figure 2 As shown, the electronic device includes: a processor 210, at least one communication bus 250, a user interface 240, at least one external communication interface 230, and a memory 220. The communication bus 250 is configured to enable communication between these components. The user interface 240 may include a display screen, and the external communication interface 230 may include standard wired and wireless interfaces. The processor 210 is configured to execute a data management program based on a relational database stored in the memory to implement the steps in the relational database-based data management provided in the above embodiment.
[0073] It should be noted that the descriptions of the above storage medium and electronic device embodiments are similar to the descriptions of the above method embodiments, and have similar beneficial effects. For technical details not disclosed in the storage medium and device embodiments of this application, please refer to the descriptions of the method embodiments of this application for understanding.
[0074] Based on the foregoing embodiments, this application provides a data management device based on a relational database. The various modules and units included in the device can be implemented by a processor in a computer device; of course, they can also be implemented by specific logic circuits. In the implementation process, the processor can be a central processing unit (CPU), a microprocessor (MPU), a digital signal processor (DSP), or a field programmable gate array (FPGA), etc.
[0075] This application provides a control device, such as... Figure 2 As shown, the data management device 221 based on a relational database includes:
[0076] Setting module 2211 is used to set the primary key of the data table, including start time and end time fields;
[0077] The database creation module 2212 establishes relationships between the primary keys of multiple data tables to form a relational database, wherein the primary keys are primary keys that do not include start time and end time fields;
[0078] The first determining module 2213 is used to determine the time when the data is entered into the data table and record the start time field corresponding to the data.
[0079] The second determining module 2214 is used to determine the time when the data needs to be deleted and record it in the corresponding end time field of the data.
[0080] The query module 2215 is used to query the first target data in the data table by inputting the first target filter condition when a data search is required. The first target filter condition includes a first condition, which is related to the end time field.
[0081] Display module 2216 is used to display the first target data in the data table obtained by query, and the first target data is sorted by the start time field.
[0082] It should be noted that, in the embodiments of this application, if the above-mentioned data management based on a relational database is implemented as a software functional module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiments of this application, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), magnetic disks, or optical disks. Thus, the embodiments of this application are not limited to any specific hardware and software combination.
[0083] Accordingly, this application provides a storage medium storing a computer program thereon, characterized in that the computer program, when executed by a processor, implements the steps in the data management method based on a relational database provided in the above embodiments.
[0084] It should be understood that the phrase "one embodiment" or "an embodiment" throughout the specification means that a specific feature, structure, or characteristic related to the embodiment is included in at least one embodiment of this application. Therefore, "in one embodiment" or "in an embodiment" appearing throughout the specification does not necessarily refer to the same embodiment. Furthermore, these specific features, structures, or characteristics can be combined in any suitable manner in one or more embodiments. It should be understood that in the various embodiments of this application, the sequence numbers of the above-described processes do not imply a sequential order of execution; the execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application. The sequence numbers of the above-described embodiments are merely descriptive and do not represent the superiority or inferiority of the embodiments.
[0085] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0086] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely illustrative. For example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods, such as: multiple units or components can be combined, or integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the various components shown or discussed can be through some interfaces, and the indirect coupling or communication connection between devices or units can be electrical, mechanical, or other forms.
[0087] The units described above as separate components may or may not be physically separate. The components shown as units may or may not be physical units. They may be located in one place or distributed across multiple network units. Some or all of the units may be selected to achieve the purpose of this embodiment according to actual needs.
[0088] In addition, each functional unit in the various embodiments of this application can be integrated into one processing unit, or each unit can be a separate unit, or two or more units can be integrated into one unit; the integrated unit can be implemented in hardware or in the form of hardware plus software functional units.
[0089] Those skilled in the art will understand that all or part of the steps of the above method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it performs the steps of the above method embodiments. The aforementioned storage medium includes various media that can store program code, such as mobile storage devices, read-only memory (ROM), magnetic disks, or optical disks.
[0090] Alternatively, if the integrated units described above are implemented as software functional modules and sold or used as independent products, they can also be stored in a computer-readable storage medium. Based on this understanding, the technical solutions of the embodiments of this application, or the parts that contribute to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a controller to execute all or part of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as mobile storage devices, ROMs, magnetic disks, or optical disks.
[0091] The above description is merely an embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A data management method based on a relational database, characterized in that, The method includes: The primary key of the data table includes start time and end time fields; A relational database is formed by establishing relationships between the primary keys of multiple data tables, wherein the primary keys do not include the start time and end time fields; Determine the time when the data is entered into the data table and record the corresponding start time field; Determine the time when data needs to be deleted and record it in the corresponding end time field of the data so that the current data lifecycle ends, thus preventing deletion and setting foreign keys; When you need to perform a data search, enter the first target filter condition to retrieve the first target data in the data table. The first target filtering condition includes a first condition, which is related to the end time field; The first target data in the retrieved data table is sorted by the start time field.
2. The method according to claim 1, characterized in that, When determining the time for entering data into the data table and recording the corresponding start time field, the end time field is blank; The first condition is that the end time field is blank.
3. The method according to claim 1, characterized in that, The method further includes: When you need to query historical data, enter the second target filter conditions to query the second target data in the data table. The second target filter conditions include conditions related to the primary key except for the end time field. The second target data in the queried data table is sorted by the start time field.
4. The method according to claim 1, characterized in that, The method further includes: When data in a data table needs to be modified, follow these steps. The first target data is obtained by performing the data novelty search. Identify the data to be modified in the first target data set; Once it is determined that the data to be modified needs to be deleted, the time when it is determined that the data to be modified needs to be deleted is recorded in the corresponding end time field; Enter the modified data into the corresponding data table, determine the time when the modified data was entered into the data table, and record it in the start time field corresponding to the modified data.
5. The method according to claim 1, characterized in that, The data table does not include foreign keys.
6. A data management device based on a relational database, characterized in that, include: The settings module is used to set the primary key of the data table, including the start time and end time fields; The database creation module establishes relationships between the primary keys of multiple data tables to form a relational database. The primary keys are those that do not include the start time and end time fields. The first determination module is used to determine the time when the data is entered into the data table and record the corresponding start time field of the data. The second determination module is used to determine the time when data needs to be deleted and record it in the corresponding end time field of the data, so that the current data life cycle ends and no deletion operation is performed, and no foreign key is set. The query module is used to query the first target data in the data table when a data search is required. The first target filter condition includes a first condition, which is related to the end time field. The display module is used to display the first target data in the data table obtained from the query. The first target data is sorted by the start time field.
7. An electronic device, characterized in that, include: A memory and a processor, wherein the memory stores a computer program that, when executed by the processor, performs the data management method based on a relational database as claimed in any one of claims 1 to 5.
8. A storage medium, characterized in that, The computer program stored in the storage medium can be executed by one or more processors and can be used to implement the data management method based on a relational database as claimed in any one of claims 1 to 5.
Citation Information
Patent Citations
Database Performance Analysis
US20130275372A1
System and method for selecting rows from dimensional databases
WO1999023585A1