Enumeration dictionary-based database data dictionary automatic generation method and system
Patent Information
- Application Number
- CN202611111277.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-24
- Publication Date
- 2026-10-30
AI Technical Summary
对于枚举定义存储在独立字典表的情形,现有工具无法在元数据采集阶段自动建立字段与字典表中枚举记录之间的关联,仍需人工介入完成字段到枚举类型的映射、枚举值的查询校验以及最终文档的合成
[0014]采用集中式枚举字典表统一存储全系统所有枚举类型的定义,设立枚举键字段、枚举存储值字段、枚举显示标签字段和枚举排序序号字段。枚举键作为全局唯一标识,使得同一种枚举类型在全系统内仅存在一份权威定义。将枚举键标记按照预设格式嵌入目标数据库字段的注释文本中,字段通过注释即携带其所引用的枚举类型标识,无需在数据库层面建立外键约束或在字段上添加额外的物理元数据,实现字段与枚举定义之间的轻量级关联。在数据字典生成过程中,通过解析字段注释并识别标记,可依据枚举键直接在枚举字典表中定位到对应的枚举类型定义,完成从字段到枚举类型的一次性自动映射。这种方式消除了在多个数据表中反复填写和维护相同枚举值列表的需要,枚举定义的任何更新只需在枚举字典表中修改一次,所有引用该枚举键的字段均能自动反映出最新的枚举值内容,从根本上解决了分散维护带来的不一致和数据冗余问题。对字段注释内容进行标记扫描处理,检测枚举键标记起始符,提取候选枚举键并与枚举字典表中已存储的枚举键执行精确匹配校验,在匹配成功后将候选枚举键确定为有效枚举键标记。然后再以提取到的枚举键标记作为查询条件,在枚举字典表中按枚举排序序号进行升序排序,获取包含枚举存储值与枚举显示标签对应关系的有序枚举值列表。这个流程将标记提取与真实性校验结合,仅当标记在枚举字典表中存在已注册的枚举定义时才被采纳,避免了字段注释中误填或遗留无效标记导致生成错误数据字典的风险。在合成阶段,将标准元数据中的字段基本信息、约束信息与通过标记查询获得的枚举值列表进行关联组合,形成包含字段属性描述和枚举取值范围描述的字段完整描述数据,并按照数据库、表和字段的层级从属关系进行组织,最终输出的数据字典条目不仅体现数据库结构的完整元数据,还自动附带了每个枚举字段对应的全部可选枚举值及其显示标签,中间无需任何人工干预。合成的内容中包含枚举显示标签和排序序号,使数据字典文档在直接可读性和有序性方面均符合实际查阅习惯。整个过程将元数据提取、枚举标记解析、枚举值去中心化查询和文档化合成高度自动化,显著降低大规模数据库枚举字段数据字典的编制工作量和维护成本。
Smart Images

Figure CN123011854A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of database management and automated document generation technology, specifically to a method and system for automated generation of database data dictionaries based on enumerated dictionaries. Background Technology
[0002] A database data dictionary is a crucial reference document describing the database structure, field attributes, and value constraints. In business systems containing numerous enumeration type fields, the definitions of enumeration values are typically scattered across application code, configuration files, and verbal agreements. Compiling a data dictionary requires manual review of database structure definitions, application source code, and business documentation to match and organize the scattered enumeration value information with the fields. Existing data dictionary generation tools generally rely on field annotations and data type information provided by database system tables, only extracting basic metadata and failing to automatically parse the range of enumeration values referenced by fields. For scenarios where field annotations contain lists of enumeration values, tools lack centralized management and unified maintenance capabilities for enumeration value definitions, often resulting in inconsistent annotation information and outdated updates for similar enumeration fields across different tables. When enumeration definitions are stored in independent dictionary tables, existing tools cannot automatically establish the association between fields and enumeration records in the dictionary table during the metadata collection phase, still requiring manual intervention to complete the mapping from fields to enumeration types, query and validate enumeration values, and synthesize the final document. As the system grows in size and the number of enumeration types increases, manual maintenance and compilation become inefficient and prone to errors, and the generated data dictionary may contain missing enumeration values or be misrepresented.
[0003] In a decentralized management model, modifications to enumeration definitions require synchronized adjustments to field comments or external documentation across multiple business tables. This lack of a single, reliable source increases consistency issues in database maintenance and data dictionary updates. The solution lies in how to lightweightly associate enumeration types with database fields while maintaining unified management of enumeration definitions, and how to automatically inject enumeration values during metadata extraction to generate a complete data dictionary containing a detailed list of enumeration value ranges. Summary of the Invention
[0004] This invention provides a method and system for automatically generating a database data dictionary based on an enumeration dictionary. It establishes a centralized enumeration dictionary table in a public or designated database as the sole storage for enumeration definitions across the entire system. Enumeration keys are embedded in the field comments of the target database using lightweight tags. During metadata extraction and parsing, the tags are automatically identified, and the corresponding enumeration value list is retrieved from the enumeration dictionary table. Finally, the standard metadata and enumeration value information are combined to output data dictionary entries containing complete field descriptions and detailed lists of enumeration value ranges, achieving fully automated generation of the data dictionary under centralized control of enumeration definitions.
[0005] To achieve the above objectives, the present invention provides the following technical solution: The present invention provides an automated method for generating a database data dictionary based on an enumeration dictionary, comprising: creating a centralized enumeration dictionary table in a public management database or any designated database, wherein the enumeration dictionary table is used to uniformly store the definitions of all enumeration types in the entire system; embedding enumeration key markers in the field comments of the target database, wherein the enumeration key markers are used to point to the corresponding enumeration type definitions in the enumeration dictionary table; establishing a data connection between the target database and the enumeration dictionary table, and extracting the standard metadata of the target database; parsing the comment content of each field in the target database, identifying and extracting the enumeration key markers in the comment content; performing an enumeration value list query operation in the enumeration dictionary table according to the extracted enumeration key markers, and obtaining the enumeration value list corresponding to the enumeration key markers; and performing data synthesis processing on the standard metadata and the obtained enumeration value list to generate complete data dictionary entries for the target database. This method separates the unified definition storage of enumeration values from the tag references in field comments. By embedding concise enumeration key tags in field comments, and in conjunction with a centralized enumeration dictionary table created once, it realizes the automated generation of the data dictionary. This avoids the tedious operation of manually consulting external documents repeatedly to complete the meaning of enumeration values during the data dictionary generation process, significantly reduces maintenance costs, and ensures the consistency and accuracy of enumeration value interpretations throughout the data dictionary.
[0006] As a technical solution of this invention, when creating a centralized enumeration dictionary table in a public management database or any designated database, a table creation statement is executed to create the enumeration dictionary table, which is independent of the business data table. An enumeration key field, an enumeration stored value field, an enumeration display label field, and an enumeration sorting number field are set in the enumeration dictionary table, and the enumeration key field is used as the primary key index of the enumeration dictionary table. The enumeration key field stores a globally unique enumeration key that identifies an enumeration type; the enumeration stored value field stores the enumeration value actually stored in the database; the enumeration display label field stores the display label of the enumeration value; and the enumeration sorting number field defines the display order of the enumeration value in the data dictionary document. By establishing an independent dictionary structure containing sorting numbers and display labels, not only is it ensured that the enumeration values are displayed in the final document according to business habits, but the mapping relationship between the storage form of the enumeration values and the business-readable form is also persistently and centrally managed.
[0007] Preferably, when embedding enumeration key markers in the field comments of the target database, all business fields in the target database that need to store enumeration values are obtained; the enumeration key corresponding to the enumeration type of each business field is written into the field comment of the business field according to a preset comment marker format, the comment marker format including a marker start character, an enumeration key name, and a marker end character; after the enumeration key marker in the field comment, a field business description text is appended, the field business description text is separated from the enumeration key marker by a preset separator, the field business description text is used to describe the business meaning of the business field. Further, when embedding the enumeration key markers in the field comments, if the same field needs to reference multiple enumeration types, multiple independent enumeration key markers are embedded sequentially in the field comment according to the preset separator. This method directly embeds the reference information of the enumeration value into the database's own structure, realizing the self-descriptive capability of fields and enumeration types, enabling the automated parsing program to accurately locate the enumeration definition referenced by the field without relying on external configuration.
[0008] As another technical solution of the present invention, when establishing a data connection between the target database and the enumeration dictionary table and extracting the standard metadata of the target database, pre-configured database connection parameters are read, and a connection session with the target database is established according to the database connection parameters; a metadata query instruction is sent to the system information database of the target database to query and extract database-level basic information, table-level basic information, and field-level basic information. The field-level basic information includes field name, field data type, field length constraint, field nullability attribute, and field default value. Based on this, a constraint information query instruction is further sent to the system information database of the target database to extract the constraint information of each table. The constraint information includes a primary key constraint field list, a foreign key constraint field list and their associated parent table and parent table fields, a uniqueness constraint field list, and check constraint condition text; the extracted constraint information of each field is associated and bound with the field-level basic information to generate a field metadata structure containing constraint annotations; then, a hierarchical mapping relationship is established between the field metadata structure and the table to which the field belongs to form the standard metadata. This technology automatically gathers the basic metadata and constraint information required for the data dictionary, providing a complete data foundation for the subsequent generation of formal data dictionary entries containing rich integrity constraint descriptions.
[0009] Preferably, the process of parsing the annotation content of each field in the target database and identifying and extracting the enumeration key marker includes: traversing all fields of all tables in the target database and sequentially reading the annotation text content of each field; performing a marker scanning process on the read annotation text content to detect whether it contains a preset enumeration key marker start character; when the annotation text content contains the enumeration key marker start character, extracting the substring from the marker start character to the corresponding marker end character as a candidate enumeration key; performing an exact match verification between the candidate enumeration key and all enumeration keys stored in the enumeration dictionary table; if the match is successful, the candidate enumeration key is determined as a valid enumeration key marker for the field. This process, by scanning specific markers in the annotation text and performing verification matching with the enumeration dictionary table, achieves automatic identification of enumeration references, effectively filters out interference from invalid characters that may appear in the annotations, and ensures the accuracy of the extraction results.
[0010] Furthermore, when retrieving the corresponding enumeration value list based on the extracted enumeration key marker, the extracted enumeration key marker is used as a query condition to execute a structured query statement in the enumeration dictionary table, filtering out data records whose enumeration key field values are equal to the enumeration key marker; the filtered data records are then sorted in ascending order based on the enumeration sorting index field to obtain an ordered enumeration value record set; the enumeration storage value field value and enumeration display label field value of each record are sequentially read from the ordered enumeration value record set to form the enumeration value list, which contains the correspondence between enumeration storage values and enumeration display labels. By using the sorting index in the dictionary table for ascending order, it is ensured that the display order of enumeration items in the final generated data dictionary entries completely matches the logical order defined by the business logic.
[0011] When performing data synthesis processing between the standard metadata and the enumeration value list obtained from the query, the basic field information and field constraint information of each field are extracted from the standard metadata to construct a basic field description segment. This basic field description segment is then associated and combined with the corresponding enumeration value list to generate complete field description data containing field attribute descriptions and enumeration value range descriptions. Following the hierarchical relationship between database, table, and field levels, the complete field description data for each field is hierarchically organized to generate complete data dictionary entries. These entries include a description of the database and table hierarchy, a basic attribute description for each field, and a detailed list of enumeration values for each field. This synthesis process automatically and seamlessly merges static database metadata with dynamically interpreted enumeration value lists. The final output data dictionary document fully reflects the type, constraints, business meaning, and optional enumeration value details of each field, greatly improving the practicality and readability of the data dictionary.
[0012] This invention also provides an automated database data dictionary generation system based on an enumerated dictionary, including a memory, a processor, and a computer program stored in the memory and running on the processor. When the processor executes the computer program, it implements the steps of the automated database data dictionary generation method based on an enumerated dictionary. This system can automatically complete the entire process from enumerated dictionary creation and field tag parsing to the synthesis of complete dictionary entries, generating a high-quality data dictionary containing accurate enumerated mapping relationships without manual intervention, effectively ensuring document timeliness and consistency in data asset description.
[0013] The technical effects and advantages provided by the present invention in the above technical solution are as follows:
[0014] A centralized enumeration dictionary table is used to uniformly store the definitions of all enumeration types in the entire system. It includes fields for enumeration key, enumeration stored value, enumeration display label, and enumeration sorting number. The enumeration key serves as a globally unique identifier, ensuring that only one authoritative definition exists for each enumeration type throughout the system. The enumeration key marker is embedded in the comment text of the target database fields according to a preset format. The field carries the identifier of the enumeration type it references through the comment, eliminating the need for foreign key constraints at the database level or additional physical metadata on the field, thus achieving a lightweight association between the field and the enumeration definition. During the data dictionary generation process, by parsing the field comments and recognizing the marker, the corresponding enumeration type definition can be directly located in the enumeration dictionary table based on the enumeration key, completing a one-time automatic mapping from field to enumeration type. This approach eliminates the need to repeatedly fill in and maintain the same enumeration value list across multiple data tables. Any update to the enumeration definition only needs to be modified once in the enumeration dictionary table, and all fields referencing that enumeration key automatically reflect the latest enumeration value content, fundamentally solving the inconsistency and data redundancy problems caused by decentralized maintenance. The process involves scanning the field comments to detect the start character of the enumeration key marker, extracting candidate enumeration keys, and performing an exact match verification with the enumeration keys already stored in the enumeration dictionary table. If a match is successful, the candidate enumeration key is confirmed as a valid enumeration key marker. Then, using the extracted enumeration key markers as query conditions, the enumeration dictionary table is sorted in ascending order by enumeration sorting number to obtain an ordered list of enumeration values containing the correspondence between stored enumeration values and displayed enumeration labels. This process combines marker extraction with validity verification, only accepting markers that exist in a registered enumeration definition in the enumeration dictionary table. This avoids the risk of generating an incorrect data dictionary due to misfilled or invalid markers in the field comments. During the synthesis phase, the basic field information and constraint information in the standard metadata are associated and combined with the list of enumeration values obtained through tag queries to form complete field description data containing field attribute descriptions and enumeration value range descriptions. This data is organized according to the hierarchical relationship between databases, tables, and fields. The final output data dictionary entries not only reflect the complete metadata of the database structure but also automatically include all possible enumeration values and their display tags for each enumeration field, requiring no manual intervention. The synthesized content includes enumeration display tags and sorting numbers, ensuring that the data dictionary document conforms to actual browsing habits in terms of both direct readability and ordered structure. The entire process highly automates metadata extraction, enumeration tag parsing, decentralized enumeration value querying, and document synthesis, significantly reducing the workload and maintenance costs of compiling and maintaining data dictionaries for large-scale database enumeration fields. Attached Figure Description
[0015] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in this invention. For those skilled in the art, other drawings can be obtained based on these drawings.
[0016] Figure 1 This is a flowchart of a method for automatically generating database data dictionaries based on enumerated dictionaries; Figure 2 This is a flowchart of the centralized enumeration dictionary table creation process; Figure 3 This is a flowchart of the standard metadata extraction and constraint association binding process; Figure 4 This is a flowchart for extracting enumeration keys and generating an enumeration value list based on annotation content; Figure 5 This is a flowchart illustrating the process of data synthesis and processing to generate complete data dictionary entries. Detailed Implementation
[0017] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0018] See Figure 1 This invention provides an automated method for generating a database data dictionary based on an enumeration dictionary, comprising: creating a centralized enumeration dictionary table in a public management database or any designated database, wherein the enumeration dictionary table is used to uniformly store the definitions of all enumeration types in the entire system; embedding enumeration key markers in the field comments of the target database, wherein the enumeration key markers are used to point to the corresponding enumeration type definitions in the enumeration dictionary table; establishing a data connection between the target database and the enumeration dictionary table, and extracting the standard metadata of the target database; parsing the comment content of each field in the target database, identifying and extracting the enumeration key markers in the comment content; performing an enumeration value list query operation in the enumeration dictionary table according to the extracted enumeration key markers, and obtaining the enumeration value list corresponding to the enumeration key markers; and performing data synthesis processing on the standard metadata and the obtained enumeration value list to generate complete data dictionary entries for the target database.
[0019] Example 1: Create a centralized enumeration dictionary table in the public management database or any designated database. For specific implementation details, refer to [reference needed]. Figure 2 First, determine the database instance to store the enumeration dictionary table. This database instance can be a public management database or an independent database specified according to the system plan. After connecting to the selected database instance, execute the data definition statement to create an enumeration dictionary table independent of the business data tables. The table creation statement explicitly specifies the table name of the enumeration dictionary table and defines four fields for it: enumeration key field, enumeration stored value field, enumeration display label field, and enumeration sorting number field. The data type of the enumeration key field is set to variable-length string, with the length determined by the maximum length of enumeration key names in the system. The data type of the enumeration stored value field is set according to the actual format of the stored enumeration value; if the enumeration value is an integer, it is set to integer; if the enumeration value is a string, it is set to variable-length string. The data type of the enumeration display label field is set to variable-length string, with the length supporting the maximum number of characters in the display label. The data type of the enumeration sorting number field is set to integer. Use a primary key constraint clause in the table creation statement to set the enumeration key field as the primary key index of the enumeration dictionary table, ensuring the uniqueness of the enumeration key in the enumeration dictionary table through the primary key mechanism.
[0020] After table creation, the enumeration dictionary table exists as a centralized storage structure, independent of any business data table. The enumeration key field stores a globally unique enumeration key that identifies an enumeration type. Each enumeration type has a unique enumeration key in the enumeration dictionary table, which serves as the association identifier for all enumeration value records under that type. The enumeration stored value field stores the actual enumeration value stored in the database; this value is the original data value persisted by the corresponding field in the business data table. The enumeration display label field stores the display label corresponding to the enumeration value; this label is the readable text describing the enumeration value in the data dictionary document. The enumeration sorting index field defines the display order of enumeration values in the data dictionary document. By assigning an integer index to each enumeration value record in the enumeration dictionary table, the order in which the enumeration value list is arranged in ascending order when the data dictionary is subsequently generated is controlled.
[0021] In some embodiments, the table creation statement for the enumeration dictionary table also includes establishing a joint unique constraint on the enumeration key field and the enumeration stored value field to prevent duplicate enumeration stored values under the same enumeration type. Optionally, the enumeration dictionary table can utilize the database's comment function to add comments to each field, explaining the purpose of the field to facilitate understanding by maintenance personnel. It can be understood that after the enumeration dictionary table is created, definition data for all enumeration types in the entire system can be inserted into it. Each data record corresponds to an enumeration value in an enumeration type, including the enumeration key, enumeration stored value, enumeration display label, and sorting number.
[0022] Example 2: Embed an enumeration key tag in the field comment of the target database. In specific implementations, by traversing the field information in the system information repository of the target database, all business fields in the target database that need to store enumeration values are acquired. During the traversal process, the field name and field comment of each field are read from the field table of the system information repository, and the business fields storing enumeration values are screened out according to a pre-maintained enumeration field list or the naming convention of field names. The enumeration field list is a configuration file that lists the fully qualified names of all business fields whose values come from a finite set of enumeration values; the naming convention may be that the field name contains a specific suffix or prefix, for example, a field ending with "_code" is regarded as an enumeration field.
[0023] After acquiring the business fields, for each business field, the enumeration key corresponding to the enumeration type corresponding to the business field is determined. The enumeration key is a globally unique string that identifies the enumeration type in the enumeration dictionary table. The manners for determining the enumeration key include: looking up according to the mapping configuration table of business fields and enumeration types, where the mapping configuration table records the correspondence between the fully qualified names of business fields and the enumeration keys; or generating according to a unified naming rule, for example, using the business field name from which the prefix and suffix are removed and converted into uppercase form as the enumeration key.
[0024] After the enumeration key is determined, an enumeration key tag string conforming to a preset comment tag format is generated. The preset comment tag format includes a tag start identifier, an enumeration key name, and a tag end identifier. The tag start identifier is a specific sequence of characters, and the tag end identifier is another specific sequence of characters. The tag start identifier and the tag end identifier appear in pairs, and are used to wrap the enumeration key name, so that a parsing program can accurately identify the enumeration key tag from the field comment text. In one embodiment, the tag start identifier adopts "<<ENUM:", and the tag end identifier adopts ">>". The enumeration key name directly uses the determined enumeration key string, which is placed between the start identifier and the end identifier. The generated enumeration key tag string does not contain spaces.
[0025] After the enumeration key tag string is generated, the business description text of the business field is acquired. The business description text is pre-written by a designer, and is used to describe the meaning and purpose of the business field at the business level. The business description text and the enumeration key tag string are separated by a preset delimiter. The preset delimiter is one or more pre-agreed characters, which plays a role in distinguishing the enumeration key tag from the business description text in the field comment. In specific implementations, the delimiter is set to two consecutive space characters, or set to a specific symbol such as a vertical line "|", and it is agreed that no extra spaces are added before and after the delimiter to avoid parsing ambiguity.
[0026] The enumeration key marker string and the business description text are concatenated in the following order: enumeration key marker first, delimiter centered, and business description text last, forming the final field comment content. The specific concatenation format is: start marker, enumeration key name, end marker, delimiter, and business description text. After concatenation, the database's field comment modification statement is used to write the field comment content into the comment column of the corresponding business field in the target database. After the database system persists this comment content, any subsequent operation reading the field comment can retrieve the embedded enumeration key marker and business description text.
[0027] In some embodiments, if the value of the same business field belongs to multiple different enumeration types simultaneously, that is, the value of a field needs to reference multiple enumeration types for joint description, then multiple independent enumeration key markers are embedded sequentially in the field comment according to a preset delimiter. Specifically, for the business field, the enumeration key corresponding to each enumeration type is obtained sequentially, and multiple independent enumeration key marker strings are generated according to the comment marker format. Then, these enumeration key marker strings are concatenated using a preset delimiter. The delimiter used here can adopt a different convention than the delimiter used to separate the enumeration key markers and the business description text mentioned above. For example, a comma "," can be used to separate multiple enumeration key markers. The concatenated content is: first enumeration key marker, comma delimiter, second enumeration key marker, comma delimiter... until the last enumeration key marker. After that, after the last enumeration key marker, the business description text of the field is appended using the delimiter used to separate the enumeration key markers and the business description text. When the parser reads this field comment, it can scan out multiple discrete enumeration key marker strings by using the start and end markers, and match them with the enumeration dictionary table to obtain a list of all corresponding enumeration values.
[0028] Example 3: Establish a data connection between the target database and the enumeration dictionary table, and extract the standard metadata from the target database. For specific implementation details, refer to [reference needed]. Figure 3The system reads pre-configured database connection parameters, which are stored in a system configuration file or a set of environment variables. The configuration file can be a key-value pair property file, a YAML file, or a JSON file. The set of environment variables consists of operating system environment variables or variables injected by the container orchestration platform. Database connection parameters include the target database's address, port, instance name, username, and authentication information. The target database address is the network address of the host machine hosting the database server, represented by an IP address or a fully qualified domain name. The target database port is the transport layer port number that the database service listens on; it is an integer value, with a default value determined by the database type. The target database instance name is the identifier for the database instance, used to distinguish multiple database instances on the database server. The username is the login account name created within the database system, and the authentication information is the password or key file path corresponding to the username. When reading database connection parameters, the system parses the configuration file or reads the environment variables, loading the various parameter values into the memory structure.
[0029] A connection session with the target database is established based on the database connection parameters. The connection session establishment process includes: locating the network endpoint of the target database using the address and port specified in the database connection parameters; specifying the database instance to connect to using the instance name; encapsulating the username and authentication information into an authentication data structure and sending it to the target database for authentication. Once the target database successfully authenticates the user, it returns a session handle, and the connection session is successfully established. The session handle is used to maintain the context state for all subsequent interactions with the target database.
[0030] After a successful connection, a metadata query command is sent to the target database's system information repository. The system information repository is a metadata storage area maintained internally by the target database management system; different database management systems have different names for it, but in relational databases it is usually called the information schema or data dictionary. The structured query statement for the metadata query command is as follows: sqlSELECTTABLE_SCHEMA,TABLE_NAME,TABLE_TYPE,ENGINE,TABLE_COLLATIONFROMINFORMATION_SCHEMA.TABLESWHERETABLE_SCHEMA=$database_name Here, `$database_name` is the target database name obtained from the database connection parameters. This name is obtained by the application after establishing a connection by calling the current database retrieval function provided by the database system. The above query statement retrieves table-level information for the specified database from the TABLES view in the system information repository. It queries and extracts basic database-level, table-level, and field-level information of the target database from the system information repository. The extraction of basic database-level information includes sending a system command to the target database to retrieve database attributes or querying the database attribute view in the system information repository to obtain the database name and database character set. The database name is the database identifier used by the current connection. The database character set is the name of the database's default character encoding scheme, such as UTF8, GBK, Latin1, etc. The extraction of basic table-level information is achieved through the above query of the TABLES view. Basic table-level information includes the table name, table type, and table storage engine. The table name is the identifier for each table within the database; the table type is a type identifier such as a base table or view; the table storage engine is the name of the database table's storage engine, such as InnoDB, MyISAM, etc.
[0031] The extraction of basic field-level information is achieved by sending a field information query command to the system database. The query command is executed against the COLUMNS view in the system database, with conditions limited to the current database schema. The basic field-level information returned by the query includes the field name, field data type, field length constraint, field nullability attribute, and field default value. The field name is the name identifier for each column in the table. The field data type is a data type defined by the database system, such as VARCHAR, INT, DECIMAL, DATETIME, etc. The field length constraint is a length or precision description attached to the type; for VARCHAR, it is the maximum number of characters, and for DECIMAL, it is the total number of digits and the number of decimal places. The field nullability attribute is a Boolean value or a string flag indicating whether nullable values are allowed, such as "YES" indicating that null values are allowed, and "NO" indicating that null values are prohibited. The field default value is a default value expression or constant automatically filled by the database system when a record is inserted and no value is specified.
[0032] After querying and extracting the database-level, table-level, and field-level basic information of the target database from the system information repository, a constraint information query command is sent to the target database's system information repository to extract the constraint information of each table in the target database. The constraint information query command involves constraint-related views in the system information repository, including the TABLE_CONSTRAINTS, KEY_COLUMN_USAGE, REFERENTIAL_CONSTRAINTS, and CHECK_CONSTRAINTS views. From the TABLE_CONSTRAINTS view, the constraint name, constraint type, and the name of the table to which it belongs are obtained; from the KEY_COLUMN_USAGE view, the list of fields covered by each constraint is obtained; from the REFERENTIAL_CONSTRAINTS view, the name of the parent table associated with the foreign key constraint and the parent table fields are obtained; and from the CHECK_CONSTRAINTS view, the constraint condition text for checking constraints is obtained. The extracted constraint information includes a list of primary key constraint fields, a list of foreign key constraint fields and their associated parent tables and parent table fields, a list of uniqueness constraint fields, and the text of the check constraint conditions. The primary key constraint field list is an ordered set of one or more fields in a table that are marked as primary keys. The foreign key constraint field list is an ordered set of one or more fields in a table that are marked as foreign keys. The parent table and its fields specify the target table and target field referenced by the foreign key. The uniqueness constraint field list is an ordered set of one or more fields for which a unique constraint is applied. The constraint condition text is a string of conditional expressions applied to a field, describing the allowed range of values for that field.
[0033] The extracted constraint information of each field is associated and bound with its corresponding field-level basic information. The association and binding operation uses the field name as the association key, merging constraint information and field-level basic information belonging to the same field into a single data structure. For primary key constraints, a boolean primary key marker and the primary key field's order position in the composite primary key are added to the field's metadata record. For foreign key constraints, a foreign key marker, the name of the referenced parent table, and the name of the referenced parent table field are added to the field's metadata record. For uniqueness constraints, a unique constraint marker is added to the field's metadata record. For check constraints, check constraint text is appended to the field's metadata record. After the association and binding operation is completed, a field metadata structure containing constraint annotations is generated. The field metadata structure uses fields as the basic unit, aggregating the field's name, data type, length constraint, nullability attribute, default value, primary key marker, foreign key reference information, unique constraint marker, and check constraint text.
[0034] Establish a hierarchical mapping relationship between the field metadata structure and the table to which the field belongs, so as to form standard metadata. The process of establishing the hierarchical mapping relationship is as follows: taking the table name in the table-level basic information as a node, mount the field metadata structures of all fields belonging to the table under the corresponding table node; then mount all table nodes under the database node represented by the database-level basic information. Thus, a three-layer tree structure of database layer, table layer and field layer is formed. The database layer node includes the database name and database character set attribute. The table layer node includes the table name, table type and table storage engine attribute, and holds a reference list of the field layer nodes. The field layer node is the field metadata structure. The entire three-layer tree structure is output as standard metadata for subsequent enumeration value synthesis processing.
[0035] Embodiment 4: In a specific implementation, refer to Figure 4 , parse the comment content of each field in the target database, and identify and extract the enumeration key mark in the comment content. Traverse all fields of all tables in the target database, and read the comment text content of each field. The traversal process is performed table by table and field by field according to the hierarchical structure in the standard metadata constructed in Embodiment 3. For each field, the content of the field comment column recorded in its field metadata structure is obtained as the comment text content. If the comment column of a certain field is a null value, the subsequent mark scanning process is skipped, and the next field is directly processed.
[0036] Perform mark scanning processing on the read comment text content, and detect whether the comment text content contains a preset enumeration key mark start character. The preset enumeration key mark start character is a specific character sequence, which is defined as "<<ENUM:" in Embodiment 2. The mark scanning process is implemented by finding the first occurrence position of the mark start character in the comment text content. The scanning algorithm adopts a string inclusion judgment function, takes the mark start character as a parameter, and performs substring positioning in the comment text content. If the first occurrence index of the mark start character is located, it is determined that the comment text content contains the enumeration key mark start character.
[0037] When an enumeration key start character is detected in the comment text, the substring from the start character to the corresponding end character is extracted as a candidate enumeration key. The end character is a specific character sequence paired with the start character, defined as ">>" in Example 2. The extraction process is as follows: obtain the starting index of the first occurrence of the start character, add the character length of the start character to the starting index to obtain the starting position of the enumeration key content; starting from the starting position of the enumeration key content, find the first occurrence of the end character in the comment text to obtain the ending position of the enumeration key content; use a string truncation operation to extract the substring from the comment text content between the starting and ending positions of the enumeration key content, and this substring is the candidate enumeration key. The extracted candidate enumeration key has the start and end characters removed, retaining only the enumeration key name part in the middle. If no end character is found after the starting position of the enumeration key content, it is considered that the comment format is abnormal, the mark extraction is abandoned, and no enumeration key mark is generated for this field.
[0038] The candidate enumeration keys are subjected to exact match verification against all enumeration keys stored in the enumeration dictionary table. In the exact match verification, an enumeration key set is constructed by sending a deduplication query command to the enumeration dictionary table. The query command is: `sqlSELECT DISTINCT enumeration key field FROM enumeration dictionary table`. This query returns all unique enumeration key field values currently existing in the enumeration dictionary table. The system loads these enumeration key field values into a set data structure in memory. Using the candidate enumeration key as a parameter, an existence check is performed on the enumeration key set. The existence check uses the set inclusion operation. If the enumeration key set contains an element that is exactly the same as the candidate enumeration key, the match is successful, the candidate enumeration key is identified as a valid enumeration key for the corresponding field, and the valid enumeration key mark is associated with the field identifier and stored. If the enumeration key set does not contain an element that is exactly the same as the candidate enumeration key, the match fails, the candidate enumeration key is discarded, and a log record is generated indicating that the enumeration key referenced by the field does not exist in the enumeration dictionary table.
[0039] For fields identified as valid enumeration key markers, subsequent enumeration value list lookup operations are performed. Based on the extracted enumeration key markers, an enumeration value list lookup operation is performed in the enumeration dictionary table to obtain the enumeration value list corresponding to the enumeration key markers. The extracted enumeration key markers are used as query conditions to execute a structured query statement in the enumeration dictionary table. The structured query statement consists of: specifying the enumeration storage value field and the enumeration display label field in the SELECT clause; specifying the enumeration dictionary table in the FROM clause; setting the equality matching condition between the enumeration key field and the extracted enumeration key markers in the WHERE clause; and specifying the ascending order of the enumeration sorting index field in the ORDER BY clause. The specific query statement format is: `sql SELECT enumeration stored value field, enumeration display label field FROM enumeration dictionary table WHERE enumeration key field = extracted enumeration key label ORDER BY enumeration sorting number field ASC`. This structured query statement is sent to the database system containing the enumeration dictionary table for execution. The database system filters out all data records in the enumeration dictionary table whose enumeration key field value is exactly equal to the extracted enumeration key label, and performs an ascending sort operation on the filtered data records according to the enumeration sorting number field, resulting in an ordered enumeration value record set. The ordered enumeration value record set is a result set, where each record contains two field values: the enumeration stored value field value and the enumeration display label field value, and the records are arranged in ascending order according to the value of the enumeration sorting number field.
[0040] The enumeration value list is formed by sequentially reading the enumeration storage value field value and the enumeration display label field value of each record from the ordered enumeration value record set. The read operation is implemented by traversing the cursor of the query result set. For each record, the enumeration storage value field value is extracted as the enumeration storage value, and the enumeration display label field value is extracted as the enumeration display label. The enumeration storage value and the enumeration display label are combined into a key-value pair or tuple and added sequentially to the enumeration value list. The final enumeration value list contains the correspondence between the enumeration storage values and the enumeration display labels, and the order of the elements in the list is consistent with the enumeration sorting sequence number defined in the enumeration dictionary table. The enumeration value list is stored in association with the field identifiers for subsequent data synthesis processing.
[0041] In some embodiments, if a comment for a business field embeds multiple enumeration key markers, the marker scanning process will be executed cyclically: after finding the first marker end character, it will continue scanning from the position after that marker to the next marker start character, until the end of the comment text content, thereby extracting multiple candidate enumeration keys in sequence. Each candidate enumeration key independently performs exact match validation and enumeration value list lookup operations, ultimately generating a set of multiple enumeration value lists for that field.
[0042] Example 5: In specific implementation, please refer to Figure 5The standard metadata is combined with the list of enumerated values obtained from the query to generate a complete data dictionary entry for the target database. Basic field information and field constraint information for each field are extracted from the standard metadata to construct a basic field description segment. The standard metadata is provided by the hierarchical structure generated in Example 3, comprising a database layer, a table layer, and a field layer. For each field metadata structure in the field layer, the field name, field data type, field length constraint, field nullability attribute, and field default value are extracted; these constitute the basic field information data. Simultaneously, primary key markers, foreign key markers and reference information, unique constraint markers, and check constraint text are extracted from the field metadata structure; these constitute the field constraint information data.
[0043] The basic field information and field constraint information are organized into a basic field description section. This section uses a key-value pair structured data representation, containing: a "Field Name" key (field name string); a "Data Type" key (field data type string); a "Maximum Length" key (the part of the field length constraint related to character count or precision); a "Allow Null" key (whether the field can be null); a "Default Value" key (the string representation of the field's default value expression); a "Primary Key" key (a boolean value indicating whether the field is a primary key member); a "Foreign Key Reference" key (a string in the format "reference to main table name.main table field name" if a foreign key constraint exists, otherwise an empty string); a "Unique Constraint" key (a boolean value indicating whether the field is subject to a unique constraint); and a "Check Constraint" key (a text string representing the check constraint condition). The completed basic field description section is stored using the field identifier as the key.
[0044] The basic description segment of a field is associated and combined with the enumeration value list corresponding to that field. For each field, the enumeration value list already associated and stored in Example 4 is retrieved based on the field identifier. If a corresponding enumeration value list exists for the field, an "enumeration value list" key is appended to the basic description segment of the field, and the enumeration value list is used as the value of this key. The content of the enumeration value list is an ordered set, and each element in the set contains two subkeys: "stored value" and "display label," which are the enumeration stored value and the enumeration display label, respectively. If multiple sets of enumeration value lists exist for the same field, such as when multiple enumeration key tags are embedded in the field's annotation, a "multiple enumeration value list" key is appended to the basic description segment of the field. Its value is a list structure, where each item in the list corresponds to an enumeration type, and each item records the "enumeration key" and the enumeration value list under that enumeration key. Through the above association and combination, complete field description data containing field attribute descriptions and enumeration value range descriptions is generated. The complete field description data fully depicts the database-level definition, constraints, and business meaning of the optional values of the field.
[0045] Based on the hierarchical relationships between database, table, and field levels, the complete field description data for each field is organized hierarchically. Using the database layer node in the standard metadata as the root, the database name and character set are extracted to construct a database layer description segment. Below this segment, all tables belonging to that database are mounted. For each table, the table name, table type, and table storage engine are extracted from the table layer node in the standard metadata to construct a table layer description segment, within which a field list container is created. Below this segment, the complete field description data from each field in the table definition are mounted sequentially. This generates complete data dictionary entries.
[0046] A complete data dictionary entry includes a hierarchical description of the database and tables, a basic attribute description for each field, and a detailed list of enumeration values for each field. The database hierarchy description, titled with the database name, displays summary information such as the database character set. The table hierarchy description displays the table type and storage engine under each table name. The basic attribute description for each field lists its name, data type, length, nullability, default value, primary key identifier, foreign key reference, unique constraint identifier, and check constraint for each field. The detailed list of enumeration values lists the mapping between stored values and display labels in a table format under the corresponding field. For multiple enumeration types, the table is grouped by enumeration key, with each group displaying the complete mapping for one enumeration value.
[0047] In some embodiments, the final output format of a complete data dictionary entry is a Hypertext Markup Language (HTML) document, wherein the hierarchical structure of the database and tables is presented using nested headings and table labels, field information is displayed as table rows, and the list of enumeration values is displayed as nested tables or bulleted lists. In other embodiments, the output format of a complete data dictionary entry is a portable document format, in which the hierarchical structure description, field attribute description, and list of enumeration values are sequentially filled into the page area using a fixed layout template.
[0048] The automated database data dictionary generation system based on enumeration dictionaries includes a memory, a processor, and a computer program stored in the memory and running on the processor. The memory provides instruction and data storage space for the system, storing configuration files, database connection parameters, enumeration dictionary table access addresses, and executable instructions of the computer program. When the processor executes the computer program, it implements the steps of the automated database data dictionary generation method based on enumeration dictionaries. The processor loads the computer program from the memory, parses the program instruction sequence, and sequentially executes the following steps: creating a centralized enumeration dictionary table in a public management database or any designated database; embedding enumeration key markers in the field comments of the target database; establishing a data connection between the target database and the enumeration dictionary table and extracting standard metadata; parsing field comments to identify and extract enumeration key markers; querying the enumeration value list based on the enumeration key markers; and synthesizing the standard metadata and the enumeration value list to generate complete data dictionary entries. Intermediate data generated during processor execution, including standard metadata, basic field description segments, enumeration value lists, and complete field description data, is temporarily stored in the memory. The final generated complete data dictionary entries are written to a designated output path in the memory or sent to the data dictionary management platform via a network interface.
[0049] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any changes 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.
Claims
1. A method for automatically generating database data dictionaries based on enumerated dictionaries, characterized in that, The method includes: Create a centralized enumeration dictionary table in the public management database or any designated database. The enumeration dictionary table is used to uniformly store the definitions of all enumeration types in the entire system. Embed enumeration key markers in the field comments of the target database. The enumeration key markers are used to point to the corresponding enumeration type definition in the enumeration dictionary table. Establish a data connection between the target database and the enumeration dictionary table, and extract the standard metadata of the target database; Parse the annotation content of each field in the target database, and identify and extract the enumeration key marker in the annotation content; Based on the extracted enumeration key marker, perform an enumeration value list query operation in the enumeration dictionary table to obtain the enumeration value list corresponding to the enumeration key marker; The standard metadata and the enumerated value list obtained from the query are combined to generate a complete data dictionary entry for the target database.
2. The method for automatically generating a database data dictionary based on an enumerated dictionary according to claim 1, characterized in that, The step of creating a centralized enumeration dictionary table in a public management database or any designated database includes: Execute a table creation statement in the public management database or any of the designated databases to create the enumeration dictionary table, which is independent of the business data table; The enumeration dictionary table is configured with an enumeration key field, an enumeration stored value field, an enumeration display label field, and an enumeration sorting number field. The enumeration key field is used as the primary key index of the enumeration dictionary table. The enumeration key field is used to store an enumeration key that uniquely identifies an enumeration type. The enumeration stored value field is used to store the enumeration value actually stored in the database. The enumeration display label field is used to store the display label of the enumeration value. The enumeration sorting number field is used to define the display order of the enumeration value in the data dictionary document.
3. The method for automatically generating a database data dictionary based on an enumerated dictionary according to claim 1, characterized in that, The step of embedding enumeration key markers in field comments of the target database includes: Retrieve all business fields in the target database that require storing enumeration values; Write the enumeration key corresponding to the enumeration type of each business field into the field comment of the business field according to the preset comment mark format. The comment mark format includes a mark start character, an enumeration key name and a mark end character. In the field annotation, the field business description text is appended after the enumeration key mark. The field business description text is separated from the enumeration key mark by a preset separator. The field business description text is used to describe the business meaning of the business field.
4. The method for automatically generating a database data dictionary based on an enumerated dictionary according to claim 1, characterized in that, The step of establishing a data connection between the target database and the enumeration dictionary table, and extracting standard metadata from the target database, includes: Read the pre-configured database connection parameters, which include the address, port, instance name, username, and authentication information of the target database; A connection session with the target database is established based on the database connection parameters, and a metadata query command is sent to the system information database of the target database after the connection is successful. The database-level basic information, table-level basic information, and field-level basic information of the target database are queried and extracted from the system information database. The database-level basic information includes the database name and database character set. The table-level basic information includes the table name, table type, and table storage engine. The field-level basic information includes the field name, field data type, field length constraint, field nullability attribute, and field default value.
5. The method for automatically generating a database data dictionary based on an enumerated dictionary according to claim 4, characterized in that, After querying and extracting the database-level basic information, table-level basic information, and field-level basic information of the target database from the system information database, the method further includes: Send a constraint information query command to the system information database of the target database to extract the constraint information of each table in the target database. The constraint information includes a list of primary key constraint fields, a list of foreign key constraint fields and their associated parent table and parent table fields, a list of uniqueness constraint fields, and text for checking constraint conditions. The constraint information of each extracted field is associated and bound with the field-level basic information to generate a field metadata structure containing constraint annotations; Establish a hierarchical mapping relationship between the field metadata structure and the table to which the field belongs, forming the standard metadata.
6. The method for automatically generating a database data dictionary based on an enumerated dictionary according to claim 1, characterized in that, The process of parsing the annotation content of each field in the target database and identifying and extracting the enumeration key marker in the annotation content includes: Iterate through all fields of all tables in the target database and read the comment text content of each field in turn; The read annotation text content is subjected to a mark-scanning process to detect whether the annotation text content contains a preset enumeration key mark start character; When the annotation text content is detected to contain the enumeration key marker start character, the substring from the marker start character to the corresponding marker end character is extracted as a candidate enumeration key; The candidate enumeration key is matched against all the enumeration keys stored in the enumeration dictionary table. If a match is found, the candidate enumeration key is identified as a valid enumeration key for the field.
7. The method for automatically generating a database data dictionary based on an enumerated dictionary according to claim 2, characterized in that, The step of performing an enumeration value list query operation in the enumeration dictionary table based on the extracted enumeration key marker to obtain the enumeration value list corresponding to the enumeration key marker includes: Using the extracted enumeration key marker as a query condition, a structured query statement is executed in the enumeration dictionary table to filter out data records in the enumeration dictionary table whose enumeration key field values are equal to the enumeration key marker. The selected data records are sorted in ascending order based on the enumeration sorting index field to obtain an ordered set of enumeration value records. The enumeration storage value field value and the enumeration display label field value of each record are read sequentially from the ordered enumeration value record set to form the enumeration value list. The enumeration value list contains the correspondence between the enumeration storage value and the enumeration display label.
8. The method for automatically generating a database data dictionary based on an enumerated dictionary according to claim 1, characterized in that, The step of performing data synthesis processing on the standard metadata and the enumerated value list obtained from the query to generate complete data dictionary entries for the target database includes: Extract the basic field information and field constraint information of each field from the standard metadata to construct the basic field description segment; The basic description segment of the field is associated and combined with the enumeration value list corresponding to the field to generate complete field description data containing field attribute description and enumeration value range description; Based on the hierarchical relationship between database level, table level, and field level, the complete description data of each field is organized hierarchically to generate the complete data dictionary entries. The complete data dictionary entries include a description of the hierarchical structure of the database and tables, a description of the basic attributes of each field, and a detailed list of enumerated values for each field.
9. The method for automatically generating a database data dictionary based on an enumerated dictionary according to claim 3, characterized in that, When embedding the enumeration key marker in the field comment, if the same field needs to reference multiple enumeration types, multiple independent enumeration key markers are embedded sequentially in the field comment according to the preset separator.
10. An automated database data dictionary generation system based on enumerated dictionaries, comprising a memory, a processor, and a computer program stored in the memory and running on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the automated generation method for database data dictionary based on enumerated dictionary as described in any one of claims 1 to 9.
