JP5827260B2 - Method, apparatus and program for estimating foreign key in database - Google Patents

Method, apparatus and program for estimating foreign key in database Download PDF

Info

Publication number
JP5827260B2
JP5827260B2 JP2013060275A JP2013060275A JP5827260B2 JP 5827260 B2 JP5827260 B2 JP 5827260B2 JP 2013060275 A JP2013060275 A JP 2013060275A JP 2013060275 A JP2013060275 A JP 2013060275A JP 5827260 B2 JP5827260 B2 JP 5827260B2
Authority
JP
Japan
Prior art keywords
column
foreign key
computer
key
actual data
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
JP2013060275A
Other languages
Japanese (ja)
Other versions
JP2014186488A (en
Inventor
正樹 小俣
正樹 小俣
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Mitsubishi Electric Information Systems Corp
Original Assignee
Mitsubishi Electric Information Systems Corp
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Mitsubishi Electric Information Systems Corp filed Critical Mitsubishi Electric Information Systems Corp
Priority to JP2013060275A priority Critical patent/JP5827260B2/en
Publication of JP2014186488A publication Critical patent/JP2014186488A/en
Application granted granted Critical
Publication of JP5827260B2 publication Critical patent/JP5827260B2/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Description

本発明は、データベースにおいて外部キーを推定する方法、装置およびプログラムに関する。   The present invention relates to a method, apparatus, and program for estimating a foreign key in a database.

最近のIT動向調査によると、新規にシステムを開発する企業や業務は減少傾向にあり、既存システムの移行案件の割合が増えている。現行システムの移行案件では、システムの機能を理解するために、一般的に現行分析から始めるが、「メンテナンスされている設計書がない」「当時の設計者は既にいない」「システム利用者はシステムの機能を説明できない、または十分なヒアリングの時間がとれない」という制約があるのが現状である。この場合、プログラムのソースコードやデータベースのオブジェクトを分析することによって必要な設計情報を得る「リバースエンジニアリング技術」が重要になってくる。   According to a recent IT trend survey, companies and businesses that develop new systems are on the decline, and the ratio of existing system migration cases is increasing. In order to understand the functions of the system, the current system generally starts with the current analysis. However, “There is no design document that is maintained,” “There is no designer at that time,” “System users are systems. The current situation is that there is a restriction that the function cannot be explained or sufficient time for hearing is not available. In this case, “reverse engineering technology” that obtains necessary design information by analyzing program source code and database objects becomes important.

データベースの設計や分析において、カラム名やデータ型を規定するテーブル定義情報や、あるカラムが主キー(Primary Key、PK)または外部キー(Foreign Key、FK)であるか否かを表す情報が重要となる。特許文献1には、データベースの設計段階において、カラム間の関係を任意に指定すると、その指定に応じて外部キーを設定する方法が記載されている。   In database design and analysis, table definition information that defines column names and data types, and information that indicates whether a column is a primary key (Primary Key, PK) or a foreign key (Foreign Key, FK) are important. It becomes. Patent Document 1 describes a method of setting a foreign key in accordance with the designation of a relation between columns arbitrarily specified in a database design stage.

特表2008−524671号公報Special table 2008-524671

また、データベースの分析において、既存のデータベースオブジェクトを参照し、テーブル定義情報等を取得する技術も知られている。   Also, a technique for acquiring table definition information and the like by referring to an existing database object in database analysis is also known.

しかしながら、従来技術では、データベースオブジェクトが外部キーを表す情報を含んでいない場合に、外部キーを特定することができないという問題があった。外部キーが分からないとER図として表現できないため、分析者はテーブル間の関係を把握できず、システムを理解することも困難になる。   However, the conventional technique has a problem that the foreign key cannot be specified when the database object does not include information representing the foreign key. If the foreign key is not known, it cannot be expressed as an ER diagram, so the analyst cannot grasp the relationship between the tables and it is difficult to understand the system.

なお、カラム名等に基づいて人為的に外部キーを推定するのは現実的に不可能な場合があり、システムまたは装置を用いる方法が必須となる。たとえば、テーブル数が700、カラム数が2万〜3万となるケースがあり、このようなケースにおいて人手で外部キーの推定作業を行うと作業量が膨大となり、また推定基準のばらつき等により推定精度も低下するおそれがある。   Note that it may not be practically possible to artificially estimate a foreign key based on a column name or the like, and a method using a system or an apparatus is essential. For example, there are cases where the number of tables is 700 and the number of columns is 20,000 to 30,000. In such a case, if the foreign key is estimated manually, the amount of work becomes enormous, and the estimation is caused by variations in estimation criteria. There is a risk that the accuracy may also decrease.

この発明は、このような問題点を解決するためになされたものであり、データベースにおいてコンピュータが外部キーを推定する方法、装置およびプログラムを提供することを目的とする。   The present invention has been made to solve such a problem, and an object thereof is to provide a method, an apparatus, and a program for a computer to estimate a foreign key in a database.

上述の問題点を解決するため、この発明に係る、データベースにおいて外部キーを推定する方法は、
複数のテーブルを含むデータベースにおいて外部キーを推定する方法であって、
コンピュータが、各テーブルについて1つ以上のカラム名を取得するステップと、
コンピュータが、各テーブルの各カラムに記録された実データを取得するステップと、
コンピュータが、前記カラム名に基づき、2つのカラムからなる対をカラム結合パターンとして特定する、カラム結合パターン特定ステップと、
各カラムが外部キーであるか否かをコンピュータが推定する、外部キー推定ステップと
を備え、
前記外部キー推定ステップにおいて、各カラム結合パターンに含まれるいずれか一方のカラムについて、
‐他方のカラムが主キーであること、
‐前記一方のカラムが、そのテーブル内で唯一の主キーではないこと、および
‐前記一方のカラムに記録された実データが、すべて前記他方のカラムに記録された実データに含まれていること
を必要条件として、一方のカラムは前記他方のカラムを参照する外部キーであると推定する。
In order to solve the above-described problem, a method for estimating a foreign key in a database according to the present invention is as follows.
A method for estimating a foreign key in a database including a plurality of tables,
A computer obtaining one or more column names for each table;
A computer acquiring actual data recorded in each column of each table;
A column coupling pattern identifying step in which a computer identifies a pair of two columns as a column coupling pattern based on the column name;
A foreign key estimation step, wherein the computer estimates whether each column is a foreign key,
In the foreign key estimation step, for any one column included in each column combination pattern,
-The other column is the primary key,
-The one column is not the only primary key in the table; and-the actual data recorded in the one column are all contained in the actual data recorded in the other column. As a prerequisite, one column is presumed to be a foreign key referring to the other column.

前記カラム結合パターン特定ステップは、
前記テーブルのいずれかを参照するプログラムのソースコードにおいて、第1のテーブルの第1のカラムに記録された第1の実データと、第2のテーブルの第2のカラムに記録された第2の実データとの一致判定を行う一致判定命令を、コンピュータが前記カラム名に基づき抽出するステップと、
抽出された各一致判定命令について、前記第1のカラム及び前記第2のカラムからなる対を、コンピュータがカラム結合パターンとして特定するステップと、
を含んでもよい。
前記カラム結合パターン特定ステップは、異なるテーブルにおいて同一のカラム名を有する2つのカラムからなる対を、カラム結合パターンとして特定するステップを含んでもよい。
前記方法は、主キー推定ステップをさらに備え、
前記主キー推定ステップにおいて、各カラムについて、
‐そのカラムの実データが未定義値を含まないこと、および
‐そのカラムの実データが、カラム内で重複していないこと
を必要条件として、コンピュータがそのカラムを主キーであると推定してもよい。
前記コンピュータは、少なくとも1つのカラムを含む除外リストを記憶し、
前記外部キー推定ステップにおいて、いずれのカラムも前記除外リストに含まれていないことをさらに必要条件としてもよい。
各テーブルを含むER図をコンピュータが作成するステップをさらに備え、
前記ER図は、
各テーブルを表すエンティティと、
外部キーであるカラムのそれぞれについて、関連する2つのテーブルを関連付ける関連線と
を含んでもよい。
The column combination pattern specifying step includes:
In the source code of a program that refers to any of the tables, the first actual data recorded in the first column of the first table and the second data recorded in the second column of the second table A step in which a computer extracts a match determination command for performing a match determination with actual data based on the column name;
For each extracted match determination instruction, the computer specifies a pair consisting of the first column and the second column as a column combination pattern;
May be included.
The column combination pattern specifying step may include a step of specifying a pair consisting of two columns having the same column name in different tables as a column combination pattern.
The method further comprises a primary key estimation step,
In the primary key estimation step, for each column,
-The computer assumes that the column is a primary key, provided that the actual data for the column does not contain undefined values, and-the actual data for the column is not duplicated within the column. Also good.
The computer stores an exclusion list including at least one column;
In the foreign key estimation step, it may be further necessary that no column is included in the exclusion list.
Further comprising the step of the computer creating an ER diagram including each table;
The ER diagram is
An entity representing each table,
For each column that is a foreign key, an association line that associates two related tables may be included.

また、この発明に係る、データベースの外部キー推定装置は、上述の方法を実行するコンピュータを含む。   A database foreign key estimation apparatus according to the present invention includes a computer that executes the above-described method.

また、この発明に係るプログラムは、コンピュータに上述の方法を実行させる。   The program according to the present invention causes a computer to execute the above-described method.

この発明に係るデータベースにおいて外部キーを推定する方法、装置およびプログラムによれば、データベースの実データと、データベースのカラム名とに基づき、当該データベースの外部キーを推定することができる。   According to the method, apparatus, and program for estimating a foreign key in a database according to the present invention, the foreign key of the database can be estimated based on the actual data of the database and the column name of the database.

本発明の実施の形態1に係る外部キー推定装置の構成の例を示す図である。It is a figure which shows the example of a structure of the foreign key estimation apparatus which concerns on Embodiment 1 of this invention. テーブル定義情報の構成の例を示す図である。It is a figure which shows the example of a structure of table definition information. 実データの構成の例を示す図である。It is a figure which shows the example of a structure of real data. ソースコードの構成の例を示す図である。It is a figure which shows the example of a structure of source code. 外部キー推定装置の処理の流れを表すフローチャートである。It is a flowchart showing the flow of a process of an external key estimation apparatus. 主キー情報の例を示す図である。It is a figure which shows the example of primary key information. 実施の形態1におけるカラム結合リストの構成の例を示す図である。6 is a diagram illustrating an example of a configuration of a column combination list according to Embodiment 1. FIG. 除外リストの構成の例を示す図である。It is a figure which shows the example of a structure of an exclusion list. 実施の形態1における外部キー情報の例を示す図である。6 is a diagram illustrating an example of foreign key information in the first embodiment. FIG. 実施の形態1において、ER図情報によって表されるER図の例である。In Embodiment 1, it is an example of the ER diagram represented by ER diagram information. 実施の形態2に係る外部キー推定装置の処理の流れを表すフローチャートである。10 is a flowchart showing a process flow of the foreign key estimation apparatus according to the second embodiment. 実施の形態2におけるカラム結合リストの構成の例を示す図である。10 is a diagram illustrating an example of a configuration of a column combination list according to Embodiment 2. FIG. 実施の形態2における外部キー情報の例を示す図である。FIG. 11 is a diagram illustrating an example of foreign key information in the second embodiment.

以下、この発明の実施の形態を添付図面に基づいて説明する。
実施の形態1.
図1に、本発明の実施の形態1に係る外部キー推定装置10の構成を示す。外部キー推定装置10は、レコードおよびカラムによって構成されるテーブルを複数含むデータベースに関するデータを入力とし、そのデータベースにおいて各カラムが外部キーであるか否かを推定する装置として機能する。この機能は、本明細書に記載される方法を実行することにより実現される。外部キー推定装置10は周知のコンピュータとしての構成を含み、演算を行う演算手段20と、情報を格納する記憶手段30とを備える。演算手段20はCPU(中央処理装置)を含み、記憶手段30は半導体メモリおよびHDD(ハードディスクドライブ)等の記憶媒体を含む。
Embodiments of the present invention will be described below with reference to the accompanying drawings.
Embodiment 1 FIG.
FIG. 1 shows the configuration of foreign key estimation apparatus 10 according to Embodiment 1 of the present invention. The foreign key estimation device 10 functions as a device that receives data relating to a database including a plurality of tables composed of records and columns and estimates whether each column is a foreign key in the database. This function is achieved by performing the method described herein. The external key estimation apparatus 10 includes a configuration as a well-known computer, and includes a calculation unit 20 that performs a calculation and a storage unit 30 that stores information. The computing means 20 includes a CPU (Central Processing Unit), and the storage means 30 includes a storage medium such as a semiconductor memory and an HDD (Hard Disk Drive).

また、とくに図示しないが、外部キー推定装置10は、入力手段および出力手段を備える。入力手段は、使用者が情報を入力するために用いる手段であり、たとえばマウスやキーボード等である。出力手段は、使用者に対して情報を出力する手段であり、たとえば液晶ディスプレイ等の表示装置であるが、プリンタ等の印刷装置であってもよい。   Although not shown in particular, the external key estimation device 10 includes an input unit and an output unit. The input means is means used by the user to input information, and is, for example, a mouse or a keyboard. The output means is means for outputting information to the user, and is a display device such as a liquid crystal display, but may be a printing device such as a printer.

記憶手段30は、テーブル定義情報31、実データ32、ソースコード33、カラム結合リスト34、除外リスト35およびER図情報36を格納する。また、記憶手段30は、図示しない外部キー推定プログラムを格納しており、コンピュータ(とくに演算手段)は、この外部キー推定プログラムを実行することにより外部キー推定装置10として機能する。   The storage means 30 stores table definition information 31, actual data 32, source code 33, column combination list 34, exclusion list 35 and ER diagram information 36. The storage unit 30 stores an external key estimation program (not shown), and the computer (particularly the calculation unit) functions as the external key estimation device 10 by executing the external key estimation program.

図2に、テーブル定義情報31の構成の例を示す。図2には、1つのデータベースに含まれる4つのテーブルが示されている。本明細書では、各テーブルをテーブル名によって参照し、それぞれ「受注」テーブル、「受注明細」テーブル、「商品」テーブルおよび「ユーザ」テーブルと呼ぶ。テーブル定義情報31は、各テーブルについて、テーブルを一意に識別するテーブル名と、そのテーブルのカラム定義情報とを含む。カラム定義情報は、図2の例では、カラム名と、データ型と、データ長と、制約とを含む。テーブル定義情報31は、たとえばDDL(データ定義言語、Data Definition Language)を用いて表現可能である。なお、図2に示すように、カラム定義情報は各テーブルについて1つ以上のカラムを含むものである。   FIG. 2 shows an example of the configuration of the table definition information 31. FIG. 2 shows four tables included in one database. In this specification, each table is referred to by a table name, and is referred to as a “order” table, a “order details” table, a “product” table, and a “user” table, respectively. The table definition information 31 includes, for each table, a table name that uniquely identifies the table and column definition information of the table. In the example of FIG. 2, the column definition information includes a column name, a data type, a data length, and a constraint. The table definition information 31 can be expressed using, for example, DDL (Data Definition Language). As shown in FIG. 2, the column definition information includes one or more columns for each table.

カラム名は、たとえばそのテーブルにおいてカラムを一意に識別する情報である。たとえば、「受注」テーブルは、「受注番号」カラム、「先方発注番号」カラム、「受注日」カラムおよび「更新者」カラムを含む。データ型およびデータ長は、そのカラムの実データの特性を規定する情報である。制約は、そのカラムの実データに対して課される制約条件を表す。図2の例では、一部のカラムの制約として「not null」パラメータが指定されている。「not null」パラメータは、そのカラムの実データはいずれもnull値すなわち未定義値であってはならないという制約を表し、空白は、そのような制約が課されていないことを表す。この他の制約が指定されてもよく、たとえばそのカラムの実データがカラム内で重複してはならないという制約を表す「unique」パラメータが指定されてもよい。   The column name is information for uniquely identifying a column in the table, for example. For example, the “order received” table includes an “order received number” column, a “first order number” column, an “order received date” column, and an “updater” column. The data type and data length are information that defines the characteristics of the actual data of the column. The constraint represents a constraint condition imposed on the actual data of the column. In the example of FIG. 2, a “not null” parameter is specified as a constraint on some columns. The “not null” parameter represents a constraint that none of the actual data in the column should be null or undefined values, and a blank indicates that no such constraint is imposed. Other constraints may be specified, for example, a “unique” parameter indicating a constraint that the actual data of the column should not be duplicated in the column.

図3に、実データ32の構成の例を示す。なお図3には「受注」テーブルおよび「商品」テーブルの例のみ示している。実データ32は、各テーブルのレコードごとに、各カラムに記録された値(すなわち各セルに記録された値)を表すデータを含む。   FIG. 3 shows an example of the configuration of the actual data 32. FIG. 3 shows only an example of an “order” table and a “product” table. The actual data 32 includes data representing a value recorded in each column (that is, a value recorded in each cell) for each record of each table.

図4に、ソースコード33の構成の一部の例を示す。ソースコード33は、データベースに含まれるテーブルのいずれかを参照するプログラムのソースコードである。複数のソースコードが含まれてもよい。このようなプログラムの例としては、ビューやDAO(Data Access Objects)等のプログラムが挙げられる。図4には3つのSELECT文が示されており、それぞれWHERE節においてカラム結合条件(テーブル結合条件と呼ぶ場合もある)を指定している。   FIG. 4 shows an example of a part of the configuration of the source code 33. The source code 33 is a source code of a program that refers to any of the tables included in the database. Multiple source codes may be included. Examples of such programs include programs such as views and DAO (Data Access Objects). FIG. 4 shows three SELECT statements, each specifying a column join condition (sometimes called a table join condition) in the WHERE clause.

カラム結合条件は、第1のテーブルの第1のカラムに記録された第1の実データと、第2のテーブルの第2のカラムに記録された第2の実データとの一致判定を行う一致判定命令により表現されるということができる。図4において、最初に出現するSELECT文を例として説明すると、「受注明細」テーブルの「商品No」カラムと、「商品」テーブルの「商品コード」カラムとを組み合わせた結合条件が指定されており、これらのカラムの実データの一致判定の結果に基づいてSELECT文が実行されることになる。なお、SELECT文やWHERE節に限らず、同等の一致判定を行う命令であればカラム結合条件を表現することが可能である。   The column join condition is a match for determining the match between the first actual data recorded in the first column of the first table and the second actual data recorded in the second column of the second table. It can be said that it is expressed by a determination instruction. In FIG. 4, the SELECT statement that appears first is described as an example. A combination condition is specified that combines the “Product No” column of the “Order Details” table and the “Product Code” column of the “Product” table. The SELECT statement is executed based on the result of the coincidence determination of the actual data in these columns. Note that the column join condition can be expressed as long as it is an instruction that makes an equivalent match determination, not limited to the SELECT statement and the WHERE clause.

カラム結合リスト34、除外リスト35およびER図情報36については、外部キー推定装置10の動作の説明に伴って後に説明する。   The column combination list 34, the exclusion list 35, and the ER diagram information 36 will be described later along with the operation of the foreign key estimation apparatus 10.

以上のように構成される外部キー推定装置10の処理の流れを以下に説明する。
図5は、実施の形態1に係る外部キー推定装置10の処理の流れを表すフローチャートである。なお説明の便宜上、各ステップの入出力についても破線を用いて一部図示してある。
The processing flow of the foreign key estimation apparatus 10 configured as described above will be described below.
FIG. 5 is a flowchart showing a process flow of foreign key estimation apparatus 10 according to the first embodiment. For convenience of explanation, part of the input / output of each step is also illustrated using broken lines.

まず、外部キー推定装置10はテーブル定義情報31を取得する(ステップS1)。この処理は、たとえば図示のようにデータベースオブジェクトを参照してテーブル定義情報31を抽出してもよいし、または、テーブル定義情報31に相当する情報を直接取得してもよい。なお、図2に示すように、取得されるテーブル定義情報31は、各テーブルについて1つ以上のカラム名を含むものである。   First, the foreign key estimation device 10 acquires table definition information 31 (step S1). In this processing, for example, the table definition information 31 may be extracted with reference to a database object as shown in the figure, or information corresponding to the table definition information 31 may be directly acquired. As shown in FIG. 2, the acquired table definition information 31 includes one or more column names for each table.

次に、外部キー推定装置10は、各テーブルの各カラムに記録された実データ32を取得する(ステップS2)。   Next, the foreign key estimation device 10 acquires the actual data 32 recorded in each column of each table (step S2).

次に、外部キー推定装置10は、取得した実データ32に基づき、各カラムが主キーであるか否かを推定する(ステップS3、主キー推定ステップ)。ここで、外部キー推定装置10は、各テーブルの各カラムについて、次の2条件を必要条件として、そのカラムが主キーであると推定する。
‐主キー条件1:そのカラムの実データが未定義値を含まない。
‐主キー条件2:そのカラムの実データが、カラム内で重複していない(すなわち、カラム内ですべて互いに異なっている)。
Next, the foreign key estimation device 10 estimates whether or not each column is a primary key based on the acquired actual data 32 (step S3, primary key estimation step). Here, the foreign key estimation apparatus 10 estimates that each column of each table is a primary key, using the following two conditions as necessary conditions.
-Primary key condition 1: The actual data of the column does not contain an undefined value.
-Primary key condition 2: The actual data of the column is not duplicated in the column (that is, they are all different from each other in the column).

なお、本明細書において、「必要条件」および「十分条件」という用語は、数学または論理学の分野における通常の意味に解される。または、たとえば次のように解されてもよい。
「A,BおよびCを必要条件としてXと推定する」という表現は、Xと推定されるためにはA,BおよびCのすべてが満たされることが最低限要求されるが、さらに他の条件が追加で要求される可能性を否定しないということを意味する。すなわち、A,BおよびCがすべて満たされた場合には、他の条件に応じ、Xと推定される場合もあればXでないと推定される場合もある。一方で、A,BおよびCのいずれかが満たされない場合には、他の条件に関わらず、Xではないと推定される。
「Aを十分条件としてXと推定する」という表現は、Xと推定されるためにはAさえ満たされればよく、他の条件が追加で要求される可能性はないということを意味する。すなわち、Aが満たされた場合には、他の条件に関わらず、必ずXと推定される。一方で、Aが満たされない場合には、他の条件に応じ、Xと推定される場合もあればXでないと推定される場合もある。
当然ながら、ある推定処理に対して、ある条件(または複数の条件の組合せ)を、必要条件とすると同時に十分条件とすることも可能である。
In the present specification, the terms “necessary conditions” and “sufficient conditions” are understood to have ordinary meanings in the field of mathematics or logic. Or, for example, it may be interpreted as follows.
The expression “estimate X with A, B, and C as prerequisites” requires that all of A, B, and C be satisfied in order to be estimated as X, but still other conditions Does not deny the possibility of being additionally required. That is, when all of A, B, and C are satisfied, it may be estimated as X or may not be X depending on other conditions. On the other hand, when any of A, B, and C is not satisfied, it is estimated that it is not X regardless of other conditions.
The expression “estimate X with A as a sufficient condition” means that in order to be estimated as X, only A needs to be satisfied and no other conditions may be required. That is, when A is satisfied, X is always estimated regardless of other conditions. On the other hand, if A is not satisfied, it may be estimated as X or may not be X depending on other conditions.
Of course, for a certain estimation process, a certain condition (or a combination of a plurality of conditions) can be a necessary condition and a sufficient condition.

主キー条件1は、たとえばテーブル定義情報31において、そのカラムの制約に「not null」パラメータが指定されているか否かに基づいて判定することができる。または、そのカラムの実データをすべて直接参照し、未定義値が含まれているか否かを確認して判定してもよい。
主キー条件2は、たとえばテーブル定義情報31において、そのカラムの制約に「unique」パラメータが指定されているか否かに基づいて判定することができる。または、そのカラムの実データをすべて直接参照し、重複するデータが存在するか否かを確認して判定してもよい。
The primary key condition 1 can be determined based on, for example, whether or not the “not null” parameter is specified for the constraint of the column in the table definition information 31. Alternatively, it may be determined by directly referring to all the actual data of the column and checking whether or not an undefined value is included.
The primary key condition 2 can be determined based on, for example, whether or not the “unique” parameter is specified for the constraint of the column in the table definition information 31. Alternatively, all the actual data of the column may be directly referred to, and it may be determined by checking whether there is duplicate data.

実施の形態1では、この推定において、上記の2条件が満たされることを十分条件とする。図3の例では、「受注」テーブルの「受注番号」カラムの実データと、「商品」テーブルの「商品コード」カラムの実データが、上記の2条件をいずれも満たすので、これらのカラムが主キーであると推定される。   In the first embodiment, in this estimation, it is a sufficient condition that the above two conditions are satisfied. In the example of FIG. 3, the actual data in the “order number” column of the “order” table and the actual data in the “product code” column of the “product” table satisfy both of the above two conditions. Presumed to be the primary key.

なお、変形例として、上記の2条件以外に追加の必要条件を課してもよい。たとえば、次の各条件のいずれかまたは任意の組合せを追加の必要条件としてもよい。
‐そのカラムについてインデックスが存在している。
‐そのカラムのデータ型が、日付または日時を表すものではない。
‐そのカラムのカラム名が所定の条件を満たす。たとえば、主キーを表す可能性が高い所定の文字列を含む。どのような文字列が主キーを表す可能性が高いかは当業者が適宜決定可能であるが、たとえば、「コード」「ID」「連番」「No」「番号」等の文字列である。
As a modification, additional necessary conditions other than the above two conditions may be imposed. For example, one or any combination of the following conditions may be set as an additional requirement.
-An index exists for the column.
-The data type of the column does not represent a date or date / time.
-The column name of the column satisfies a predetermined condition. For example, a predetermined character string that is highly likely to represent a primary key is included. A person skilled in the art can appropriately determine what kind of character string is likely to represent the primary key. For example, it is a character string such as “code”, “ID”, “serial number”, “No”, “number”, etc. .

このステップS3において、外部キー推定装置10は、各カラムが主キーであると推定されたか否かを表す主キー情報を出力する。
図6に、主キー情報の例を示す。この例では、主キー情報は、テーブル定義情報31において各カラムのカラム定義に追加されるフラグの形式で表されているが、他の形式で表されてもよく、たとえばテーブル定義情報31とは独立したファイルとして記憶されてもよい。
In step S3, the foreign key estimation device 10 outputs primary key information indicating whether each column is estimated to be a primary key.
FIG. 6 shows an example of primary key information. In this example, the primary key information is represented in the form of a flag added to the column definition of each column in the table definition information 31, but may be represented in other formats, for example, the table definition information 31 It may be stored as an independent file.

次に実行されるステップS4〜S6が、実施の形態1におけるカラム結合パターン特定ステップを構成する。実施の形態1において、カラム結合パターン特定ステップは、ソースコード33に基づいて、2つのカラムからなる対をカラム結合パターンとして特定するステップとして実施される。   Steps S4 to S6 executed next constitute the column combination pattern specifying step in the first embodiment. In the first embodiment, the column combination pattern specifying step is performed as a step of specifying a pair of two columns as a column combination pattern based on the source code 33.

ステップS3の後、外部キー推定装置10は、ソースコード33を取得する(ステップS4)。
次に、外部キー推定装置10は、ソースコード33から、カラムの一致判定命令を抽出する(ステップS5)。たとえば、テーブル定義情報31に含まれるカラム名に基づき(またはテーブル名およびカラム名に基づき)、ソースコード33において、第1のテーブルの第1のカラムに記録された第1の実データと、第2のテーブルの第2のカラムに記録された第2の実データとの一致判定を行う一致判定命令を抽出する。結果として、たとえば図4に示す3つのSELECT文が特定される。
After step S3, the foreign key estimation device 10 acquires the source code 33 (step S4).
Next, the foreign key estimation device 10 extracts a column match determination command from the source code 33 (step S5). For example, based on the column name included in the table definition information 31 (or based on the table name and the column name), in the source code 33, the first actual data recorded in the first column of the first table, the first The coincidence determination command for performing the coincidence determination with the second actual data recorded in the second column of the second table is extracted. As a result, for example, three SELECT statements shown in FIG. 4 are specified.

次に、外部キー推定装置10は、抽出された一致判定命令のそれぞれについて、カラム結合パターンを特定して記憶する(ステップS6)。カラム結合パターンは、一致判定命令に含まれる2つのカラムからなる対として特定されるものであり、たとえばカラム結合リスト34に記憶される。このようにして、実施の形態1におけるカラム結合パターン特定ステップが終了する。
図7に、実施の形態1におけるカラム結合リスト34の構成の例を示す。この例では、図4の3つのSELECT文に対応するカラム結合パターンが示されている。
Next, the foreign key estimation device 10 specifies and stores a column combination pattern for each of the extracted match determination instructions (step S6). The column combination pattern is specified as a pair consisting of two columns included in the match determination instruction, and is stored in, for example, the column combination list 34. In this way, the column combination pattern specifying step in the first embodiment is completed.
FIG. 7 shows an example of the configuration of the column combination list 34 in the first embodiment. In this example, column combination patterns corresponding to the three SELECT statements in FIG. 4 are shown.

次に、外部キー推定装置10は、各カラム結合パターンについて、各カラムが外部キーであるか否かを推定する(ステップS7、外部キー推定ステップ)。たとえば、各カラム結合パターンについて、一方のカラム(以下「外部キー候補」と称する場合がある)に対し、次の4条件を必要条件として、その外部キー候補は他方のカラムを参照する外部キーであると推定する。
‐外部キー条件1:他方のカラムが主キーである。たとえば、図7に示す3つのカラム結合パターンのうち第1のものにおいて、「商品」テーブルの「商品コード」カラムは主キーであるので(図6参照)、「受注明細」テーブルの「商品No」カラムは外部キー候補として外部キー条件1を満たす。
‐外部キー条件2:外部キー候補であるカラムは、そのテーブル内で唯一の主キーではない。すなわち、そのテーブルは、主キーを含まないか、外部キー候補以外に主キーを含む。
‐外部キー条件3:外部キー候補であるカラムに記録された実データが、他方のカラムに記録された実データと整合している。すなわち、外部キー候補であるカラムに記録された実データが、すべて他方のカラムに記録された実データに含まれている。
‐外部キー条件4:いずれのカラムも、除外リスト35に含まれていない。
Next, the foreign key estimation device 10 estimates whether or not each column is a foreign key for each column combination pattern (step S7, foreign key estimation step). For example, for each column combination pattern, the following four conditions are required for one column (hereinafter sometimes referred to as “foreign key candidate”), and the foreign key candidate is a foreign key that refers to the other column. Presume that there is.
Foreign key condition 1: the other column is the primary key. For example, in the first of the three column combination patterns shown in FIG. 7, the “product code” column in the “product” table is the primary key (see FIG. 6), so “product No.” in the “order details” table. The column satisfies the foreign key condition 1 as a foreign key candidate.
-Foreign key condition 2: A column that is a foreign key candidate is not the only primary key in the table. That is, the table does not include a primary key or includes a primary key in addition to a foreign key candidate.
-Foreign key condition 3: The actual data recorded in the column that is a foreign key candidate is consistent with the actual data recorded in the other column. That is, the actual data recorded in the column that is a foreign key candidate is all included in the actual data recorded in the other column.
Foreign key condition 4: None of the columns are included in the exclusion list 35.

図8に、除外リスト35の構成の例を示す。除外リスト35は、たとえば使用者によって事前に準備される。除外リスト35は、1つ以上のカラムについて、そのカラムを特定する情報(たとえばテーブル名とカラム名との組合せ)を含むものである。図8の例では、除外リスト35に「ユーザ」テーブルの「更新者」カラムが含まれている。   FIG. 8 shows an example of the configuration of the exclusion list 35. The exclusion list 35 is prepared in advance by a user, for example. The exclusion list 35 includes information for specifying one or more columns (for example, a combination of a table name and a column name). In the example of FIG. 8, the exclusion list 35 includes the “updater” column of the “user” table.

この推定において、上記の4条件が満たされることを十分条件としてもよく、また、これら以外に追加の必要条件を課してもよい。追加の必要条件としては、たとえば、「外部キー候補であるカラムのデータ型およびデータ長と、他方のカラムのデータ型およびデータ長とがいずれも一致している」という条件を用いることができる。   In this estimation, the above four conditions may be satisfied sufficiently, and additional necessary conditions may be imposed in addition to these conditions. As an additional necessary condition, for example, a condition that “a data type and a data length of a column that is a foreign key candidate, and a data type and a data length of the other column all match” can be used.

このように、ステップS7においてソースコード33の情報を用いるので、対となるカラムのカラム名がテーブル間で一致していない場合や、カラム名に共通する文字列が一切含まれない場合であっても、カラム結合パターンを抽出することが可能である。また、逆に、カラム名が一致していても、実データが整合していない場合には、外部キーでないと正しく推定することが可能である。   As described above, since the information of the source code 33 is used in step S7, the column names of the paired columns do not match between the tables, or the character string common to the column names is not included at all. It is also possible to extract the column binding pattern. Conversely, even if the column names match, if the actual data is not consistent, it can be correctly estimated that the key is not a foreign key.

このステップS7において、外部キー推定装置10は、各カラムが外部キーであると推定されたか否かを表す外部キー情報を出力する。
図9に、実施の形態1における外部キー情報の例を示す。この例では、外部キー情報は、テーブル定義情報31において各カラムのカラム定義に追加されるフラグの形式で表されている。
In step S7, the foreign key estimation device 10 outputs foreign key information indicating whether each column is estimated to be a foreign key.
FIG. 9 shows an example of foreign key information in the first embodiment. In this example, the foreign key information is represented in the form of a flag added to the column definition of each column in the table definition information 31.

「受注明細」テーブルの「受注番号」カラムについて、カラム結合パターンにおける他方のカラム(「受注」テーブルの「受注番号」カラム)は主キーであり、外部キー条件1を満たす。また、「受注明細」テーブルには2つの主キーが含まれており、外部キー条件2を満たす。また、ここでは、「受注明細」テーブルの「受注番号」カラムに記録された実データが、他方のカラム(「受注」テーブルの「受注番号」カラム)の実データと整合しており、外部キー条件3を満たすと仮定する。また、ここでは、「受注明細」テーブルの「受注番号」カラムが除外リスト35に含まれておらず、外部キー条件4を満たすと仮定する。この場合、このカラムは図9に示すように外部キーであると推定されることになる。   Regarding the “Order Number” column in the “Order Details” table, the other column in the column combination pattern (“Order Number” column in the “Order” table) is the primary key and satisfies the foreign key condition 1. The “order details” table includes two primary keys and satisfies the foreign key condition 2. Here, the actual data recorded in the “Order Number” column in the “Order Details” table is consistent with the actual data in the other column (“Order Number” column in the “Order” table), and the foreign key Assume that condition 3 is satisfied. Here, it is assumed that the “order number” column of the “order details” table is not included in the exclusion list 35 and satisfies the foreign key condition 4. In this case, this column is assumed to be a foreign key as shown in FIG.

また、「受注明細」テーブルの「商品No」カラムについて、カラム結合パターンにおける他方のカラム(「商品」テーブルの「商品コード」カラム)は主キーであり、外部キー条件1を満たす。また、「受注明細」テーブルには2つの主キーが含まれており、外部キー条件2を満たす。また、ここでは、「受注明細」テーブルの「商品No」カラムに記録された実データが、他方のカラム(「商品」テーブルの「商品コード」カラム)の実データと整合しており、外部キー条件3を満たすと仮定する。また、ここでは、「受注明細」テーブルの「商品No」カラムが除外リスト35に含まれておらず、外部キー条件4を満たすと仮定する。この場合、このカラムは図9に示すように外部キーであると推定されることになる。   For the “product No” column of the “order details” table, the other column in the column combination pattern (the “product code” column of the “product” table) is the primary key and satisfies the external key condition 1. The “order details” table includes two primary keys and satisfies the foreign key condition 2. Here, the actual data recorded in the “Product No.” column of the “Order Details” table is consistent with the actual data of the other column (“Product Code” column of the “Product” table), and the foreign key Assume that condition 3 is satisfied. Here, it is assumed that the “product number” column of the “order details” table is not included in the exclusion list 35 and satisfies the foreign key condition 4. In this case, this column is assumed to be a foreign key as shown in FIG.

なお、厳密に言えば、図9に示される情報は外部キー情報の一部のみであり、カラム間の関係を十分に特定するためには、図9に示される情報に加え、カラム結合リスト34(図7)等を参照して各外部キーが参照しているカラムを特定する必要がある。
外部キー情報は、他の形式で表されてもよく、たとえばテーブル定義情報31とは独立したファイルとして記憶されてもよい。
Strictly speaking, the information shown in FIG. 9 is only a part of the foreign key information, and in order to sufficiently specify the relationship between the columns, in addition to the information shown in FIG. It is necessary to specify the column referred to by each foreign key with reference to FIG.
The external key information may be expressed in other formats, and may be stored as a file independent of the table definition information 31, for example.

次に、外部キー推定装置10は、ER図を作成する(ステップS8)。この処理は、たとえばER図情報36を出力することによって行われる。ER図情報36は、図1のように記憶手段30に出力され記憶されてもよいし、図示しない表示装置または印刷装置等に出力されてもよい。   Next, the foreign key estimation device 10 creates an ER diagram (step S8). This process is performed, for example, by outputting ER diagram information 36. The ER diagram information 36 may be output and stored in the storage unit 30 as shown in FIG. 1, or may be output to a display device or a printing device (not shown).

図10に、ER図情報36によって表されるER図の例を示す。図10の例では、ER図は、各テーブルを表すエンティティ36aと、各テーブルに含まれるカラムのカラム名と、各カラムが主キーであるか否かを示す表示と、各カラムが外部キーであるか否かを示す表示と、外部キーである各カラムについて関連する2つのテーブルを関連付ける関連線36bおよび36cとを含む。ここで、「関連するテーブル」とは、外部キーであるカラムを含むテーブルと、その外部キーが参照するカラムを含むテーブルとを意味する。   FIG. 10 shows an example of the ER diagram represented by the ER diagram information 36. In the example of FIG. 10, the ER diagram includes an entity 36a representing each table, a column name of a column included in each table, a display indicating whether each column is a primary key, and each column having a foreign key. It includes a display indicating whether or not there is, and association lines 36b and 36c for associating two related tables for each column which is a foreign key. Here, the “related table” means a table including a column that is a foreign key and a table including a column that is referenced by the foreign key.

図10の例では、「(主キー)」という表記があるカラムは主キーであり、この表記がないカラムは主キーではない。外部キーについても同様である。また、主キーであるカラムのグループと、主キーでないカラムのグループとを互いに分離して配置している(図10の例では、水平線によって上下に分離されている)。   In the example of FIG. 10, a column with the notation “(primary key)” is a primary key, and a column without this notation is not a primary key. The same applies to foreign keys. Further, a group of columns that are primary keys and a group of columns that are not primary keys are separated from each other (in the example of FIG. 10, they are separated vertically by a horizontal line).

さらに、ER図は、関連線36bおよび36cについて、外部キーを含む側のテーブルを特定する表現を含む。この例では外部キー側の端点が大きく表現されている。また、外部キーを含む側のテーブルが、他方のテーブルに依存するか否かを示す表現を含む。ここで、「依存」とは、外部キーが主キーでもあることを意味し、一方、「非依存」とは、外部キーが主キーではないことを意味する。図10の例では、「受注明細」テーブルの「受注番号」カラムは外部キーかつ主キーであるので、この外部キーに対応する関連線36bは「依存」の関係を表すものとして実線で表現されている。一方、「受注明細」テーブルの「商品No」カラムは外部キーであるが主キーではないので、この外部キーに対応する関連線36cは「非依存」の関係を表すものとして破線で表現されている。   Further, the ER diagram includes an expression for specifying the table on the side including the foreign key for the relation lines 36b and 36c. In this example, the end point on the foreign key side is greatly expressed. In addition, the table including the foreign key includes an expression indicating whether or not it depends on the other table. Here, “dependent” means that the foreign key is also a primary key, while “independent” means that the foreign key is not the primary key. In the example of FIG. 10, since the “order number” column in the “order details” table is a foreign key and a primary key, the related line 36b corresponding to this foreign key is represented by a solid line as representing a “dependent” relationship. ing. On the other hand, since the “Product No.” column of the “Order Details” table is a foreign key but not a primary key, the relation line 36c corresponding to this foreign key is represented by a broken line as representing an “independent” relationship. Yes.

以上説明するように、本発明の実施の形態1に係る外部キーを推定する方法、外部キー推定装置10および外部キー推定プログラムによれば、データベースの実データ32と、データベースを参照するプログラムのソースコード33(とくにカラム名)とに基づき、当該データベースの外部キーを推定することができる。   As described above, according to the method for estimating a foreign key, the foreign key estimating apparatus 10 and the foreign key estimating program according to the first embodiment of the present invention, the actual data 32 of the database and the source of the program referring to the database Based on the code 33 (particularly the column name), the foreign key of the database can be estimated.

なお、本発明は、人間が行っている業務を単にシステム化するものではない。外部キーの推定作業は、作業量が膨大となるケースがあり、そのようなケースでは人間が業務として行うのは現実的に不可能であるため、コンピュータによる実施が不可欠である。   It should be noted that the present invention does not simply systemize the work performed by humans. The external key estimation work may be enormous in the amount of work, and in such a case, it is practically impossible for a human to perform the work, so implementation by a computer is indispensable.

実施の形態2.
実施の形態2は、実施の形態1において、カラム結合パターン特定ステップ(図5のステップS4〜S6)の構成を変更するものである。以下、実施の形態1との相違点を説明する。
図11は、実施の形態2に係る外部キー推定装置の処理の流れを表すフローチャートである。なお説明の便宜上、各ステップの入出力についても一部図示してある。
Embodiment 2. FIG.
The second embodiment changes the configuration of the column combination pattern specifying step (steps S4 to S6 in FIG. 5) in the first embodiment. Hereinafter, differences from the first embodiment will be described.
FIG. 11 is a flowchart showing a process flow of the foreign key estimation apparatus according to the second embodiment. For convenience of explanation, part of the input / output of each step is also shown.

ステップS3の後に実行されるステップS14が、実施の形態2におけるカラム結合パターン特定ステップを構成する。ステップS14において、外部キー推定装置は、各テーブルのカラム定義情報を参照し、異なるテーブルにおいて同一のカラム名を有する2つのカラムを抽出する。そして、抽出されたカラムからなる対を、カラム結合パターンとして特定する。   Step S14 executed after step S3 constitutes the column combination pattern specifying step in the second embodiment. In step S14, the foreign key estimation apparatus refers to the column definition information of each table, and extracts two columns having the same column name in different tables. And the pair which consists of the extracted column is specified as a column coupling | bonding pattern.

なお、3つ以上の異なるテーブルに渡って同一のカラム名を有するカラムが存在する場合には、すべての可能な対をカラム結合パターンとして特定する(すなわち、n個のカラムに対してn・(n−1)/2個のカラム結合パターンが特定されることになる)。ただし、変形例として、なんらかの基準を用いて特定すべきカラム結合パターンを絞り込んでもよい。   Note that if there are columns having the same column name across three or more different tables, all possible pairs are identified as a column combination pattern (ie, n · ( n-1) / 2 column coupling patterns will be identified). However, as a modification, the column combination pattern to be specified may be narrowed down using some standard.

以下、実施の形態2において、図2に示すテーブル定義情報31に基づいて外部キー推定を実行した場合の動作を説明する。
図12に、実施の形態2において作成されるカラム結合リスト34の構成の例を示す。図2のテーブル定義情報31から、一致するカラム名の対がすべて抽出され特定されている。
Hereinafter, in the second embodiment, an operation when foreign key estimation is executed based on the table definition information 31 shown in FIG. 2 will be described.
FIG. 12 shows an example of the configuration of the column combination list 34 created in the second embodiment. All matching column name pairs are extracted and specified from the table definition information 31 of FIG.

また、図13に、実施の形態2における外部キー情報の例を示す。「受注明細」テーブルの「受注番号」カラムについては、実施の形態1と同様に外部キーであると推定されているが、「受注明細」テーブルの「商品No」カラムについては、カラム結合リスト34に含まれないため外部キーではないと推定されている。   FIG. 13 shows an example of foreign key information in the second embodiment. The “order number” column in the “order details” table is presumed to be a foreign key as in the first embodiment, but the “commodity number” column in the “order details” table is the column combination list 34. It is presumed that it is not a foreign key because it is not included in.

このように、実施の形態2ではソースコード33を参照しない。したがって、ソースコード33の一部または全部が保存されていない等の原因で、ソースコード33に基づくカラム結合リスト34の作成が実行できないまたは実行困難である場合には、実施の形態2のようにカラム名に基づく方法のほうがより適切に外部キーを推定できる場合がある。   Thus, the source code 33 is not referred to in the second embodiment. Therefore, when the creation of the column combination list 34 based on the source code 33 cannot be executed or is difficult due to a part or all of the source code 33 not being saved, as in the second embodiment. In some cases, the method based on column names can better estimate foreign keys.

以上説明するように、本発明の実施の形態2に係る外部キーを推定する方法、外部キー推定装置10および外部キー推定プログラムによれば、データベースの実データ32と、各テーブルのカラム名とに基づき、当該データベースの外部キーを推定することができる。   As described above, according to the method for estimating a foreign key, the foreign key estimation device 10 and the foreign key estimation program according to the second embodiment of the present invention, the actual data 32 of the database and the column names of each table are used. Based on this, the foreign key of the database can be estimated.

上述の実施の形態1および2において、次のような変形を施すことができる。
実施の形態1および2では、カラム定義情報は、カラム名、データ型、データ長および制約からなるが、この他の情報を含んでもよい。たとえば、各カラムが主キーであるか否かを表す情報を含んでもよい。各カラムが主キーであるか否かを表す情報が含まれている場合には、主キー判定ステップを省略してもよい(すなわち、ステップS1において主キーに関する情報を取得し、ステップS3を省略してもよい)。
In the first and second embodiments described above, the following modifications can be made.
In the first and second embodiments, the column definition information includes a column name, a data type, a data length, and constraints, but may include other information. For example, information indicating whether each column is a primary key may be included. When information indicating whether or not each column is a primary key is included, the primary key determination step may be omitted (that is, information relating to the primary key is acquired in step S1, and step S3 is omitted). You may).

また、カラム定義情報は、データ型、データ長および制約のいずれかまたはすべてを含まないものであってもよい。原理的には、カラム名を含んでいれば本発明の最低限の実施には十分である。   Further, the column definition information may not include any or all of the data type, the data length, and the constraint. In principle, including a column name is sufficient for a minimal implementation of the present invention.

除外リスト35を用いない構成であってもよい。たとえば、記憶手段30は除外リスト35を記憶せず、ステップS7において外部キー条件4(いずれのカラムも、除外リスト35に含まれていないこと)を用いない構成としてもよい。   A configuration in which the exclusion list 35 is not used may be used. For example, the storage unit 30 may not store the exclusion list 35 and may not use the foreign key condition 4 (no columns are included in the exclusion list 35) in step S7.

ER図に関する処理は省略してもよい。すなわち、外部キーを推定した時点で処理を終了し、ステップS8については実行しない形態としてもよい。
また、ER図は、図10に示すもの以外の情報を含んでもよく、図10に示す情報の一部を含まないものであってもよい。少なくとも、各テーブルを表すエンティティと、外部キーであるカラムのそれぞれについて関連する2つのテーブルを関連付ける関連線とを含んでいれば、ER図に該当すると解釈できる。
Processing related to the ER diagram may be omitted. That is, the process may be terminated when the foreign key is estimated, and step S8 may not be executed.
Further, the ER diagram may include information other than that shown in FIG. 10, or may not include a part of the information shown in FIG. If at least an entity representing each table and a relation line that associates two tables related to each of the columns that are foreign keys are included, it can be interpreted as corresponding to the ER diagram.

実施の形態2において、カラム結合パターンの特定は、カラム名に基づいて行われるものであればよく、カラム名が厳密に一致していないものまで含むようにしてもよい。たとえば、異なる2つのテーブルのカラム名が、所定長の一致する文字列を含む場合には、それらの対をカラム結合パターンとして抽出してもよい。判定基準は当業者が適宜設計可能である。   In the second embodiment, the column combination pattern may be specified based on the column name, and may be included even if the column names do not exactly match. For example, when the column names of two different tables include matching character strings of a predetermined length, those pairs may be extracted as a column combination pattern. The judgment criteria can be appropriately designed by those skilled in the art.

実施の形態1および2を組み合わせてもよい。たとえば、実施の形態1のステップS4〜S6で特定されるカラム結合パターンと、実施の形態2のステップS14で特定されるカラム結合パターンとを結合してもよい。すなわち、それぞれのカラム結合リストをOR結合してもよい。この場合、図7および図12の例では、合計で12個のカラム結合パターンが特定され、カラム結合リスト34に含まれることになる。   Embodiments 1 and 2 may be combined. For example, the column combination pattern specified in steps S4 to S6 of the first embodiment and the column combination pattern specified in step S14 of the second embodiment may be combined. That is, each column combination list may be ORed. In this case, in the example of FIGS. 7 and 12, a total of 12 column combination patterns are specified and included in the column combination list 34.

また、実施の形態1のステップS4〜S6においても、実施の形態2のステップS14においてもカラム結合パターンとして特定される対のみを、カラム結合リスト34に含めてもよい。すなわち、それぞれのカラム結合リストをAND結合してもよい。この場合、図7および図12の例では、図7の第2番目のもの(図12では第1番目のもの)のみ、ただ1つのカラム結合パターンが特定され、カラム結合リスト34に含まれることになる。   In addition, in steps S4 to S6 in the first embodiment and in step S14 in the second embodiment, only the pairs specified as the column combination pattern may be included in the column combination list 34. That is, each column combination list may be ANDed. In this case, in the example of FIGS. 7 and 12, only one column combination pattern is specified and included in the column combination list 34 for only the second one of FIG. 7 (first one in FIG. 12). become.

また、カラム結合リスト34の作成において、OR結合を用いるか、AND結合を用いるかを指定可能であってもよい。たとえば、外部キー推定装置10は、カラム結合リスト34の作成方法に関する指定入力(OR結合を用いよという指定またはAND結合を用いよという指定)を受け付け、これに応じて異なる条件でカラム結合リスト34を作成してもよい。   In creating the column combination list 34, it may be possible to specify whether to use an OR combination or an AND combination. For example, the foreign key estimation apparatus 10 accepts a designation input relating to a method of creating the column combination list 34 (designation of using an OR combination or designation of using an AND combination), and the column combination list 34 under different conditions according to this. May be created.

10 外部キー推定装置(コンピュータ)、20 演算手段、30 記憶手段、31 テーブル定義情報、32 実データ、33 ソースコード、34 カラム結合リスト(カラム結合パターン)、35 除外リスト、36a エンティティ、36b,36c 関連線、
S3 主キー推定ステップ、S4〜S6,S14 カラム結合パターン特定ステップ、S7 外部キー推定ステップ。
10 external key estimation device (computer), 20 computing means, 30 storage means, 31 table definition information, 32 actual data, 33 source code, 34 column join list (column join pattern), 35 exclusion list, 36a entity, 36b, 36c Related lines,
S3 primary key estimation step, S4 to S6, S14 column combination pattern identification step, S7 foreign key estimation step.

Claims (8)

複数のテーブルを含むデータベースにおいて外部キーを推定する方法であって、
コンピュータが、各テーブルについて1つ以上のカラム名を取得するステップと、
コンピュータが、各テーブルの各カラムに記録された実データを取得するステップと、
コンピュータが、前記カラム名に基づき、2つのカラムからなる対をカラム結合パターンとして特定する、カラム結合パターン特定ステップと、
各カラムが外部キーであるか否かをコンピュータが推定する、外部キー推定ステップと
を備え、
前記外部キー推定ステップにおいて、各カラム結合パターンに含まれるいずれか一方のカラムについて、
‐他方のカラムが主キーであること、
‐前記一方のカラムが、そのテーブル内で唯一の主キーではないこと、および
‐前記一方のカラムに記録された実データが、すべて前記他方のカラムに記録された実データに含まれていること
を必要条件として、一方のカラムは前記他方のカラムを参照する外部キーであると推定する、データベースにおいて外部キーを推定する方法。
A method for estimating a foreign key in a database including a plurality of tables,
A computer obtaining one or more column names for each table;
A computer acquiring actual data recorded in each column of each table;
A column coupling pattern identifying step in which a computer identifies a pair of two columns as a column coupling pattern based on the column name;
A foreign key estimation step, wherein the computer estimates whether each column is a foreign key,
In the foreign key estimation step, for any one column included in each column combination pattern,
-The other column is the primary key,
-The one column is not the only primary key in the table; and-the actual data recorded in the one column are all contained in the actual data recorded in the other column. As a prerequisite, a method for estimating a foreign key in a database in which one column is estimated to be a foreign key referring to the other column.
前記カラム結合パターン特定ステップは、
前記テーブルのいずれかを参照するプログラムのソースコードにおいて、第1のテーブルの第1のカラムに記録された第1の実データと、第2のテーブルの第2のカラムに記録された第2の実データとの一致判定を行う一致判定命令を、コンピュータが前記カラム名に基づき抽出するステップと、
抽出された各一致判定命令について、前記第1のカラム及び前記第2のカラムからなる対を、コンピュータがカラム結合パターンとして特定するステップと、
を含む、請求項1に記載の方法。
The column combination pattern specifying step includes:
In the source code of a program that refers to any of the tables, the first actual data recorded in the first column of the first table and the second data recorded in the second column of the second table A step in which a computer extracts a match determination command for performing a match determination with actual data based on the column name;
For each extracted match determination instruction, the computer specifies a pair consisting of the first column and the second column as a column combination pattern;
The method of claim 1 comprising:
前記カラム結合パターン特定ステップは、異なるテーブルにおいて同一のカラム名を有する2つのカラムからなる対を、カラム結合パターンとして特定するステップを含む、請求項1または2に記載の方法。   The method according to claim 1, wherein the column combination pattern specifying step includes a step of specifying a pair of two columns having the same column name in different tables as a column combination pattern. 前記方法は、主キー推定ステップをさらに備え、
前記主キー推定ステップにおいて、各カラムについて、
‐そのカラムの実データが未定義値を含まないこと、および
‐そのカラムの実データが、カラム内で重複していないこと
を必要条件として、コンピュータがそのカラムを主キーであると推定する、請求項1〜3のいずれか一項に記載の方法。
The method further comprises a primary key estimation step,
In the primary key estimation step, for each column,
-The computer assumes that the column is the primary key, provided that the actual data for the column does not contain undefined values, and-the actual data for the column is not duplicated within the column, The method as described in any one of Claims 1-3.
前記コンピュータは、少なくとも1つのカラムを含む除外リストを記憶し、
前記外部キー推定ステップにおいて、いずれのカラムも前記除外リストに含まれていないことをさらに必要条件とする、請求項1〜4のいずれか一項に記載の方法。
The computer stores an exclusion list including at least one column;
The method according to any one of claims 1 to 4, wherein the foreign key estimation step further requires that no column is included in the exclusion list.
各テーブルを含むER図をコンピュータが作成するステップをさらに備え、
前記ER図は、
各テーブルを表すエンティティと、
外部キーであるカラムのそれぞれについて、関連する2つのテーブルを関連付ける関連線と
を含む、請求項1〜5のいずれか一項に記載の方法。
Further comprising the step of the computer creating an ER diagram including each table;
The ER diagram is
An entity representing each table,
6. The method according to any one of claims 1 to 5, comprising a relation line that associates two related tables for each column that is a foreign key.
請求項1〜6のいずれか一項に記載の方法を実行するコンピュータを含む、データベースの外部キー推定装置。   An apparatus for estimating a foreign key of a database, comprising a computer that executes the method according to claim 1. コンピュータに、請求項1〜6のいずれか一項に記載の方法を実行させるプログラム。   The program which makes a computer perform the method as described in any one of Claims 1-6.
JP2013060275A 2013-03-22 2013-03-22 Method, apparatus and program for estimating foreign key in database Active JP5827260B2 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP2013060275A JP5827260B2 (en) 2013-03-22 2013-03-22 Method, apparatus and program for estimating foreign key in database

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP2013060275A JP5827260B2 (en) 2013-03-22 2013-03-22 Method, apparatus and program for estimating foreign key in database

Publications (2)

Publication Number Publication Date
JP2014186488A JP2014186488A (en) 2014-10-02
JP5827260B2 true JP5827260B2 (en) 2015-12-02

Family

ID=51834015

Family Applications (1)

Application Number Title Priority Date Filing Date
JP2013060275A Active JP5827260B2 (en) 2013-03-22 2013-03-22 Method, apparatus and program for estimating foreign key in database

Country Status (1)

Country Link
JP (1) JP5827260B2 (en)

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH0527960A (en) * 1991-07-24 1993-02-05 Toshiba Corp Data base constructing method
JPH07281882A (en) * 1994-04-14 1995-10-27 Mitsubishi Electric Corp Data base normalization support device
JP5601028B2 (en) * 2010-05-24 2014-10-08 日本電気株式会社 Database replication system, database replication method, information processing apparatus, and program
JP5633689B2 (en) * 2010-11-09 2014-12-03 日本電気株式会社 Database migration management apparatus and method

Also Published As

Publication number Publication date
JP2014186488A (en) 2014-10-02

Similar Documents

Publication Publication Date Title
Aguirre-Urreta et al. Sample size determination and statistical power analysis in PLS using R: an annotated tutorial
US7949938B2 (en) Comparing and merging multiple documents
TW498201B (en) System and method for generating year 2000 test cases
US9092586B1 (en) Version management mechanism for fluid guard ring PCells
EP2863311B1 (en) Domain centric test data generation
US20150324437A1 (en) Grid format data viewing and editing environment
JP2017041171A (en) Test scenario generation support device and test scenario generation support method
JP6419667B2 (en) Test DB data generation method and apparatus
WO2016063502A1 (en) Knowledge management device, knowledge management method, and program recording medium
JP2017045080A (en) Business flow specification regeneration method
US10055533B2 (en) Visualization of analysis process parameters for layout-based checks
US10241899B2 (en) Test input information search device and method
US20130006683A1 (en) System and method of managing testing for a healthcare systems transition
US8166453B2 (en) Method and system for inconsistency resolution with cycle detection in a model-driven software environment
US20160123120A1 (en) Systems, methods, and computer medium to optimize storage for hydrocarbon reservoir simulation
US20080244501A1 (en) Method for reading information from a hierarchical design
JP5827260B2 (en) Method, apparatus and program for estimating foreign key in database
JP6878804B2 (en) Information processing equipment, information processing methods, and programs
JP6549786B2 (en) Data cleansing system, method and program
Zahari et al. Data quality issues in data migration
JP2018028776A (en) Software asset management device, software asset management method, and software asset management program
JP6633009B2 (en) Table data analysis program
JP5202655B2 (en) Business flowchart search device and program
JP2016126532A (en) Calculation program, information processing apparatus, and calculation method
JP2014174921A (en) Information processing system, and name-identification determination method and program

Legal Events

Date Code Title Description
A02 Decision of refusal

Free format text: JAPANESE INTERMEDIATE CODE: A02

Effective date: 20141111

A61 First payment of annual fees (during grant procedure)

Free format text: JAPANESE INTERMEDIATE CODE: A61

Effective date: 20151015

R150 Certificate of patent or registration of utility model

Ref document number: 5827260

Country of ref document: JP

Free format text: JAPANESE INTERMEDIATE CODE: R150

R250 Receipt of annual fees

Free format text: JAPANESE INTERMEDIATE CODE: R250

R250 Receipt of annual fees

Free format text: JAPANESE INTERMEDIATE CODE: R250

R250 Receipt of annual fees

Free format text: JAPANESE INTERMEDIATE CODE: R250

R250 Receipt of annual fees

Free format text: JAPANESE INTERMEDIATE CODE: R250

R250 Receipt of annual fees

Free format text: JAPANESE INTERMEDIATE CODE: R250

R250 Receipt of annual fees

Free format text: JAPANESE INTERMEDIATE CODE: R250