JP2004133573A - System for assigning database table primary key - Google Patents

System for assigning database table primary key Download PDF

Info

Publication number
JP2004133573A
JP2004133573A JP2002295697A JP2002295697A JP2004133573A JP 2004133573 A JP2004133573 A JP 2004133573A JP 2002295697 A JP2002295697 A JP 2002295697A JP 2002295697 A JP2002295697 A JP 2002295697A JP 2004133573 A JP2004133573 A JP 2004133573A
Authority
JP
Japan
Prior art keywords
primary key
generated
name
attribute
department
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.)
Pending
Application number
JP2002295697A
Other languages
Japanese (ja)
Inventor
Yasuo Sekihara
関原 康夫
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.)
Canon Inc
Original Assignee
Canon Inc
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 Canon Inc filed Critical Canon Inc
Priority to JP2002295697A priority Critical patent/JP2004133573A/en
Publication of JP2004133573A publication Critical patent/JP2004133573A/en
Pending legal-status Critical Current

Links

Images

Landscapes

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

Abstract

<P>PROBLEM TO BE SOLVED: To provide a base table primary key assigning system for automatically generating the table primary key of a relational database through the use of a program without the manual operation of a database manager when the table primary key is generated, saving labor, and optimizing relation. <P>SOLUTION: The primary key of a table including hierarchical contents such as the department names of an enterprise, the addresses of individuals, and product classification information concerning the attributes of relation is generated in the relational database. In this case, the primary key is generated through the use of a means for referring to a field name (a string name) in an SQL sentence in the order corresponding to the attributes of the table (the string) by using a program, thereby generating a record set object. <P>COPYRIGHT: (C)2004,JPO

Description

【0001】
【発明の属する技術分野】
本発明は、リレーショナルデータベーステーブルに登録されている様々なテーブルであるリレーションに、テーブル結合等のために主キーを割り当てる際、データベース管理者がテーブルの内容を加味してキーを割りあてる負荷を削減し、データベース管理者の手を介在することなくクライアント側で容易に主キーを生成することに関するものである。
【0002】
【従来の技術】
従来、データベーステーブルに登録されている様々なリレーションに主キーを割り当てる際、データベース管理者が手作業でテーブルの内容を加味して主キーを割り当てなくてはならず、相当な時間と労を要していた。特に、テーブルの内容が企業の部署名や個人の住所、製品分類情報といった階層的な内容(例えば、部署名の場合、事業本部名、事業部名、,,課名等)である場合に顕著であった。しかも、割り当てたい値の主キーが既に割り当て済みである場合、テーブルの内容を考慮した適正な値の主キーを割り当てられなかった。
【0003】
従って、後でデータベース利用の際、手作業による主キーの再構築が必要であった。
【0004】
又、敢えてテーブルの内容を考慮した適正な値の主キーを割り当てようとした場合、既に割り当て済の主キーの値を変更しなくてはならず、手作業でテーブルをレコード単位に再編成する必要があり、データベース運用の効率が悪かった。
【0005】
【発明が解決しようとする課題】
このような場合、後でデータベース利用の際にテーブルの内容を出力しようとしたときに、折角主キーの昇順にテーブルの内容が出力されても、再度、見易くするためにも手作業でソートし直さなくてはならず効率が悪かった。
【0006】
又、データベースに、一般的には、ユーザインターフェースであるフォームを使った、データベース更新の際、一貫性の欠いた主キーをユーザに認識させざるを得ず、違和感を与えて好ましくなかった。従って、主キーに一貫性をも持たせるために、手作業による主キーの再構築が必要であった。
【0007】
本発明は上記問題に鑑みてなされたもので、その目的とする処は、リレーショナルデータベースのテーブル主キーを生成する際、データベース管理者の手によらず、プログラムにより自動的に生成し、省力化とリレーションの最適化を図ることができるベーステーブル主キー割り当て方式を提供することにある。
【0008】
【課題を解決するための手段】
上記目的を達成するため、本発明は、リレーショナルデータベースにおいて、リレーションの属性が企業の部署名や個人の住所、製品分類情報といった階層的な内容を含むテーブルの主キーを生成する際にプログラムを用い、そのテーブルの属性順に(列順に)、フィールド名(列名)をSQL文に引用し、レコードセットオブジェクトを生成する手段を用いて主キーを生成することを特徴とする。
【0009】
【発明の実施の形態】
以下に本発明の実施の形態を添付図面に基づいて説明する。
【0010】
本発明においては、リレーショナルデータベースにアクセスするプログラムの中で、レコードセットオブジェクト変数を利用し、レコードセットオブジェクト生成手段として、データベース操作言語でありデータ定義機能を持つSQL文を利用する。
【0011】
テーブルのフィールド名(列名)を引用したSQL文と、レコードセットオブジェクト変数を階層的な内容のテーブルの属性(列)の数だけ用意し、下位階層からSQL文を使ってレコードセットオブジェクトを生成する。そして、生成した結果、最終レコードの値により主キーを生成し、その主キーが既に割り当て済であれば、その1つ上の階層へと順次上位層への主キー生成を試み、最上位階層で主キーが生成できなければ主キー全体の再構築を試みる。
【0012】
図1はデータベーステーブル主キー割り当て方式を含むプログラムとユーザとのインターフェースであるフォーム及びリレーショナルデータベースの概念図である。
【0013】
5はリレーショナルデータベースであり、図3の詳細に示すユーザテーブルと所属部署テーブルがあるものとする。
【0014】
図3において、ユーザテーブルは、ユーザID、ユーザ名、Eメール、...部署キーというフィールドから成る属性を持ち、一方、所属部署テーブルは、部署キー、事業本部名、事業部名、センター名、部名、課名というフィールドから成る属性を持っている。そして、所属部署テーブルの部署キーを主キーに設定し、ユーザテーブルの外部キーとして双方のテーブルを結合している。
【0015】
今、ユーザを追加登録しようとして、そのユーザの所属部署が、所属部署テーブルに存在しない場合、ユーザテーブルのレコード(タプル)の追加とともに、所属部署テーブルにもレコードの追加をすることになり、新たに双方のテーブルを結合する際の部署キー(主キー)の生成が必要になる。その部署キーの生成を司るのが1で示すクライアントプログラムである。
【0016】
先ず、ユーザの追加登録をしようとしてクライアントプログラムを起動すると、2で示すユーザインターフェースであるフォームが表示される。フォームの詳細を図2に示す。図2において、追加するユーザを、ユーザ選択コンボボックス7或はスクロールボタン9等で選択した後(尚、ここでは、別フォームで、追加するユーザのユーザテーブルに関する情報を予め入力してあるものとする)、事業本部、事業部、...課名といった、テキストフィールド8に追加するユーザの部署名を入力する。そのとき、テキストフィールドに部署名を入力すると同時に、プログラム1で確保した10の配列変数strSQL(i)にそれをセーブする。入力完了後、フォームの“追加”ボタン6を押下すると、3で示す本発明のテーブルキー割り当て方式を実施するプログラムモジュールが起動する。
【0017】
ここで、変数iは、‘0’から、所属部署名テーブルの属性の次数までの任意の値を示す。つまり、フィールドである属性の名称が、階層的な構成になっているときの階層番号を示し、最高位の階層を‘0’とし、最低位の階層を‘n’としたi番目の階層を示しており、本実施の形態の場合、最高位の名称は“事業本部名”で、最低位の名称は“課名”である。
【0018】
プログラムモジュールの詳細を図4のフローチャートに示す。
【0019】
図4において、フォームから追加入力されたレコードの内容に、既存レコードとの重複がないかどうかチェックし、重複がない場合、11で上記変数iに最低位から1つ上の階層番号の‘n−1’を代入する。次に、先にセーブした配列変数strSQL(i)を使って、クエリー操作のためのSQL文を生成する(12)。又、SQL文の詳細を13に示す。但し、SQL文中のBLNG(i)は配列定数を示し、所属部署テーブルのフィールド名称、つまり列名をプログラムにより事前に入力しておくものとする。
【0020】
次に、14において、15で示すデータベースオブジェクト生成文により、‘n−1’階層のフィールドの属性が一致するレコードだけの集合のオブジェクトを生成する。例えば、図2の所属部署フォームにおいて、テキストフィールド8で、追加部署名として‘A事業本部’‘A事業部’‘Aセンター’‘製造部’‘生産課’と入力したとすると、‘n−1’階層の属性である部名が、“製造部”であるレコードの集合のオブジェクトを生成することを意味する。
【0021】
次に、16で示すキーの生成に際しては、上記集合のオブジェクトの最終レコードの所属キー(主キー)の次の値を採用する。上記の追加事例の場合、図3の所属部署テーブルより、最終レコードの所属キー(主キー)の値が、‘0101’であるから、採用される主キーの値は‘0102’となる。
【0022】
そして、そのキーが、所属部署テーブル全体の部署キーのどれかに重複しなければ、主キーとして確定する。もしも、重複があれば、上記変数iに、‘n−1’階層の次の階層番号番である‘n−2’を代入し、同様の操作を行い、例えば上記の追加事例の場合、‘センター名’が、‘Aセンター’であるレコードの集合のオブジェクトを生成し、最終的に上記変数iに最上位の階層番号の‘0’を代入するまでを行う。つまり、上記の追加事例の場合、‘事業本部’が‘A事業本部’であるレコードの集合のオブジェクトを生成するまでを行う。
【0023】
こうして、最終的に、主キーの重複から逃れられない場合、主キー全体を再構築する(18)。再構築の場合は、本実施の形態の場合、重複したレコード以降の主キーの値に特定の値を加算することにより主キーの重複を避けている(19)。
【0024】
こうして、生成された主キーは、ユーザテーブルと所属部署テーブルに書き込むとともに、フォームにフィードバックしてユーザに知らせしめる(20)。
【0025】
【発明の効果】
以上説明したように、本発明においては、リレーショナルデータベーステーブルのリレーションの属性が、階層的な内容になっている場合、テーブル結合等のために主キーを割り当てる際、データベース管理者がテーブルの内容を加味してキーを割りあてる負荷を削減し、データベース管理者の手を介在することなく、その場で、クライアント側で容易に主キーを生成することができ、後でデータベース利用の際、例えばテーブルの内容を出力しようとしたときに、再度、テーブルの内容をソートし直す必要がなくなるという効果が得られる。
【図面の簡単な説明】
【図1】データベーステーブル主キー割り当て方式を含むプログラムとユーザとのインターフェースであるフォーム及びリレーショナルデータベースの概念図である。
【図2】図1で示すフォームの詳細図である。
【図3】図1で示すデータベーステーブル詳細図である。
【図4】本発明に係るテーブルキー割り当て方式(プログラム)のフローチャートである。
【符号の説明】
1   クライアントプログラム
2   ユーザインターフェースフォーム
3   テーブルキー割り当て方式(プログラム)
4   主キー生成ブロック
5   データベーステーブル
6   ユーザインターフェースフォームの‘追加’ボタン
7   ユーザインターフェースフォームの‘ユーザ選択’コンボボックス
8   ユーザインターフェースフォームの‘テキスト’フィールド
9   ユーザインターフェースフォームの‘スクロール’ボタン
10  配列変数
11  変数iの初期値入力ステップ
12  SQL生成ステップ
13  SQL文詳細
14  レコードオブジェクト生成ステップ
15  レコードオブジェクト生成文詳細
16  主キー生成ステップ
17  主キー生成文詳細
18  レコード全体再構築ステップ
19  主キー生成ステップ
20  主キー確定ステップ
[0001]
TECHNICAL FIELD OF THE INVENTION
According to the present invention, when assigning a primary key to relations, which are various tables registered in a relational database table, for table joining, etc., a database administrator reduces the load of assigning keys in consideration of table contents. The present invention also relates to easily generating a primary key on the client side without the intervention of a database administrator.
[0002]
[Prior art]
Conventionally, when assigning primary keys to various relations registered in the database table, the database administrator must manually assign the primary key taking into account the contents of the table, which requires considerable time and effort. Was. This is particularly remarkable when the contents of the table are hierarchical contents such as company names, personal addresses, and product classification information (for example, in the case of a department name, the name of a business headquarters, a business unit, a section, etc.). Met. In addition, when the primary key of the value to be allocated has already been allocated, the primary key of an appropriate value in consideration of the contents of the table cannot be allocated.
[0003]
Therefore, when the database was used later, it was necessary to manually reconstruct the primary key.
[0004]
In addition, if an attempt is made to assign a primary key having an appropriate value in consideration of the contents of the table, the value of the already assigned primary key must be changed, and the table is manually reorganized in record units. Required, and the efficiency of database operation was inefficient.
[0005]
[Problems to be solved by the invention]
In such a case, if you try to output the contents of the table later when using the database, even if the contents of the table are output in ascending order of the primary key, the contents are sorted manually again for easy viewing again. I had to fix it and it was inefficient.
[0006]
In addition, when updating a database using a form, which is a user interface, in the database, the user is generally forced to recognize the inconsistent primary key, giving an uncomfortable feeling, which is not preferable. Therefore, it was necessary to manually reconstruct the primary key in order to make the primary key consistent.
[0007]
SUMMARY OF THE INVENTION The present invention has been made in view of the above problems, and a purpose thereof is to automatically generate a table primary key of a relational database by a program without relying on a database administrator, thereby saving labor. Another object of the present invention is to provide a base table primary key assignment method capable of optimizing a relation between a table and a primary key.
[0008]
[Means for Solving the Problems]
In order to achieve the above object, the present invention uses a program in a relational database to generate a primary key of a table in which relation attributes include hierarchical contents such as a department name of a company, an address of an individual, and product classification information. The field name (column name) is quoted in the SQL statement in the attribute order (column order) of the table, and the primary key is generated using a means for generating a record set object.
[0009]
BEST MODE FOR CARRYING OUT THE INVENTION
Hereinafter, embodiments of the present invention will be described with reference to the accompanying drawings.
[0010]
In the present invention, a record set object variable is used in a program for accessing a relational database, and an SQL statement which is a database operation language and has a data definition function is used as a record set object generating means.
[0011]
Prepare the SQL statement that quotes the field names (column names) of the table and the record set object variables by the number of attributes (columns) of the table with hierarchical contents, and generate the record set object from the lower hierarchy using the SQL statement I do. Then, as a result of the generation, a primary key is generated based on the value of the last record. If the primary key has already been allocated, an attempt is made to sequentially generate a primary key in the next higher hierarchy to the upper hierarchy, and the highest hierarchy. If the primary key cannot be generated by, try reconstructing the entire primary key.
[0012]
FIG. 1 is a conceptual diagram of a form and a relational database as an interface between a program and a user including a database table primary key assignment method.
[0013]
Reference numeral 5 denotes a relational database, which has a user table and a department table shown in detail in FIG.
[0014]
In FIG. 3, the user table includes user ID, user name, e-mail,. . . On the other hand, the department table has attributes composed of fields such as a department key, a business headquarters name, a business department name, a center name, a department name, and a section name. Then, the department key of the belonging department table is set as the primary key, and both tables are joined as an external key of the user table.
[0015]
Now, if an attempt is made to add a user and the department to which the user belongs does not exist in the department table, the record (tuple) of the user table is added and the record is added to the department table as well. It is necessary to generate a department key (primary key) when joining both tables. The client program indicated by 1 controls the generation of the department key.
[0016]
First, when a client program is started in order to additionally register a user, a form as a user interface indicated by reference numeral 2 is displayed. The details of the form are shown in FIG. In FIG. 2, after the user to be added is selected by the user selection combo box 7 or the scroll button 9 or the like (here, it is assumed that information on the user table of the user to be added is previously input in another form. Do), business headquarters, business division,. . . A department name of the user to be added to the text field 8, such as a section name, is input. At this time, at the same time as inputting the department name in the text field, it is saved in ten array variables strSQL (i) secured by the program 1. When the "add" button 6 of the form is pressed after the input is completed, a program module for executing the table key assignment method of the present invention indicated by 3 is started.
[0017]
Here, the variable i indicates an arbitrary value from '0' to the order of the attribute of the belonging department name table. That is, the name of the attribute, which is a field, indicates the layer number when the layer has a hierarchical structure. The i-th layer where the highest layer is "0" and the lowest layer is "n" is shown. In the case of this embodiment, the name of the highest rank is “business headquarters name” and the lowest rank is “section name”.
[0018]
Details of the program modules are shown in the flowchart of FIG.
[0019]
In FIG. 4, it is checked whether or not the content of the record additionally input from the form has an overlap with the existing record. Substitute -1 '. Next, an SQL statement for a query operation is generated using the previously saved array variable strSQL (i) (12). Details of the SQL statement are shown in FIG. However, BLNG (i) in the SQL statement indicates an array constant, and the field name of the department table, that is, the column name, is input in advance by a program.
[0020]
Next, at 14, a database object generation statement shown at 15 is used to generate an object of a set of only records having the same attribute of the field of the 'n-1' level. For example, in the department form shown in FIG. 2, if "A business headquarters", "A business department", "A center", "manufacturing department", and "production department" are entered as additional department signatures in text field 8, "n- This means that an object of a set of records whose department name, which is the attribute of the 1 'layer, is "manufacturing department" is generated.
[0021]
Next, when generating the key indicated by 16, the next value of the belonging key (primary key) of the last record of the object of the set is adopted. In the case of the additional case described above, the value of the belonging key (primary key) of the last record is “0101” from the belonging department table of FIG. 3, so the value of the adopted primary key is “0102”.
[0022]
If the key does not overlap with any of the department keys in the entire department table, the key is determined as the primary key. If there is an overlap, “n−2” which is the next layer number of the “n−1” layer is substituted for the variable i, and the same operation is performed. For example, in the case of the above additional case, The process of generating an object of a set of records in which the “center name” is “A center” is performed, and finally, “0” of the highest hierarchical number is substituted for the variable i. That is, in the case of the additional case described above, the process is performed until the “business headquarters” generates an object of a set of records that is the “business headquarters”.
[0023]
Thus, finally, if the primary key cannot be escaped, the entire primary key is reconstructed (18). In the case of reconstruction, in the case of the present embodiment, duplication of the primary key is avoided by adding a specific value to the value of the primary key after the duplicated record (19).
[0024]
The primary key thus generated is written in the user table and the department table, and is fed back to the form to inform the user (20).
[0025]
【The invention's effect】
As described above, in the present invention, when relation attributes of a relational database table have hierarchical contents, when assigning a primary key for table joining or the like, a database administrator In addition, the key allocation load can be reduced, and the primary key can be easily generated on the client side on the spot without the intervention of the database administrator. When the contents of the table are to be output, it is not necessary to sort the contents of the table again.
[Brief description of the drawings]
FIG. 1 is a conceptual diagram of a form and a relational database as an interface between a program including a database table primary key assignment method and a user.
FIG. 2 is a detailed view of the form shown in FIG.
FIG. 3 is a detailed view of a database table shown in FIG. 1;
FIG. 4 is a flowchart of a table key assignment method (program) according to the present invention.
[Explanation of symbols]
1 Client program 2 User interface form 3 Table key assignment method (program)
4 Primary key generation block 5 Database table 6 'Add' button on user interface form 7 'User selection' combo box on user interface form 8 'Text' field on user interface form 9 'Scroll' button on user interface form 10 Array variable 11 Initial value input step of variable i 12 SQL generation step 13 SQL statement details 14 Record object generation step 15 Record object generation statement details 16 Primary key generation step 17 Primary key generation statement details 18 Whole record reconstruction step 19 Primary key generation step 20 Main Key confirmation step

Claims (2)

リレーショナルデータベースにおいて、リレーションの属性が企業の部署名や個人の住所、製品分類情報といった階層的な内容を含むテーブルの主キーを生成する際にプログラムを用い、そのテーブルの属性順に(列順に)、フィールド名(列名)をSQL文に引用し、レコードセットオブジェクトを生成する手段を用いて主キーを生成することを特徴とするベーステーブル主キー割り当て方式。In a relational database, a program is used to generate a primary key of a table in which relation attributes include hierarchical contents such as a department name of a company, an address of an individual, and product classification information. A base table primary key assignment method, wherein a field name (column name) is cited in an SQL statement and a primary key is generated using a means for generating a record set object. 生成された主キーを階層的な内容のテーブルの属性順(列順)に生成し、最下位層から順次上位層へ主キー生成を試みる、つまりN−1層の属性で生成されなかったとき、N階層の属性で更にN、更にN層の属性でも生成されなかったとき、N+1階層の属性で主キー生成を試みる手段と、最終的に最上位層の属性で主キーが割り当てられなかったときに主キー全体を再構築する手段を有することを特徴とする請求項1記載のデータベーステーブル主キー割り当て方式。Generates the generated primary key in the attribute order (column order) of the hierarchical content table, and tries to generate the primary key sequentially from the lowest layer to the upper layer, that is, when the primary key is not generated with the attribute of the N-1 layer Means that an attempt is made to generate a primary key with an attribute of the (N + 1) th layer when no attribute is further generated in the attributes of the Nth and Nth layers, and that no primary key is finally assigned in the attribute of the highest layer. 2. The database table primary key assignment method according to claim 1, further comprising means for sometimes reconstructing the entire primary key.
JP2002295697A 2002-10-09 2002-10-09 System for assigning database table primary key Pending JP2004133573A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP2002295697A JP2004133573A (en) 2002-10-09 2002-10-09 System for assigning database table primary key

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP2002295697A JP2004133573A (en) 2002-10-09 2002-10-09 System for assigning database table primary key

Publications (1)

Publication Number Publication Date
JP2004133573A true JP2004133573A (en) 2004-04-30

Family

ID=32285872

Family Applications (1)

Application Number Title Priority Date Filing Date
JP2002295697A Pending JP2004133573A (en) 2002-10-09 2002-10-09 System for assigning database table primary key

Country Status (1)

Country Link
JP (1) JP2004133573A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2006031382A (en) * 2004-07-15 2006-02-02 Daiwa Securities Group Inc Database management system, program and recording medium

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2006031382A (en) * 2004-07-15 2006-02-02 Daiwa Securities Group Inc Database management system, program and recording medium

Similar Documents

Publication Publication Date Title
US7752197B2 (en) SQL query construction using durable query components
US7139774B2 (en) Singleton abstract model correspondence to multiple physical models
US7146376B2 (en) Data abstraction model driven physical layout
US8180787B2 (en) Application portability and extensibility through database schema and query abstraction
US7340480B2 (en) Iterative data analysis enabled through query result abstraction
US7689580B2 (en) Search based application development framework
US8762428B2 (en) Rapidly deploying virtual database applications using data model analysis
US6618733B1 (en) View navigation for creation, update and querying of data objects and textual annotations of relations between data objects
US7188105B2 (en) Query abstraction high level parameters for reuse and trend analysis
US7844618B2 (en) Techniques for managing interdependent data objects
US6609132B1 (en) Object data model for a framework for creation, update and view navigation of data objects and textual annotations of relations between data objects
US7844623B2 (en) Method to provide management of query output
US7979456B2 (en) Method of managing and providing parameterized queries
US20080228716A1 (en) System and method for accessing unstructured data using a structured database query environment
US10296505B2 (en) Framework for joining datasets
US20080016048A1 (en) Intelligent condition pruning for size minimization of dynamic, just in time tables
US8458215B2 (en) Dynamic functional module availability
EP1636674A2 (en) Iterative data analysis process via query result augmentation and result data feedback
JP2001350656A (en) Integrated access method for different data sources
US20050154756A1 (en) Method of generating database transaction statements based on existing queries
WO2001077904A1 (en) Framework for creation, update, query, and view navigation of data objects and textual annotations of relations between data objects
US20050278306A1 (en) Linked logical fields
US8316013B2 (en) Programmatic retrieval of tabular data within a cell of a query result
JP2004133573A (en) System for assigning database table primary key
US7991788B2 (en) Abstract data model filters