Defining and Modifying 一意キー

www.altova.com このトピックを印刷 前のページ 1つ上のレベル 次のページ

ホーム >  データベース構造の探索と変更 > デザインエディター内でのテーブルのデザイン >

Defining and Modifying 一意キー

This topic shows you how to define a 一意キー in デザインエディター ウィンドウ. You can also define a 一意キー by entering and executing the appropriate SQL statement in an SQL エディターウィンドウ.

 

When defining a 一意キー for a table, please consider that if the 一意キー制約 is applied to an existing column, this column must not contain duplicate values. The column may be nullable, however the NULL value can occur only once.

 

There are several ways to define a 一意キー in デザインエディター ウィンドウ; the procedures are similar to those described for primary keys:

 

Select the Make 一意キー command from コンテキストメニュー of a column in a table design
Drag a column from the Columns section and drop it onto the Keys section of a table design
Click the Create new キー制約 ic_add-column アイコン in the Keys section of a table design
Right-click anywhere into the table design and select 「新規の挿入 | Key | 一意キー from コンテキストメニュー

 

Regardless of the approach chosen above, the key is added to the Key section of the table design. デフォルトでは、 the name of the new 一意キー is <generated>, which means its name will be automatically generated by the database. This ensures uniqueness of the name in the database. If necessary, you can override 生成された名前. To do this, enter a descriptive name in place of <generated>, and press Enter.

 

If you override 生成された名前 with a custom name, the new name must be unique; otherwise, errors will occur when the database change script is executed.

 

As always when making changes to the database structure, a change script is generated which must be executed in order to actually create the 一意キー in the database. DatabaseSpy performs a check as to whether the content in the constrained column is unique. If the check fails, a ダイアログボックス opens displaying a "duplicate key was found" error. The exact contents of the error message depends on the database type.

dbs_create_uk_error

Columns that have a 一意キー assigned are marked with the 一意キー ic_unique-key-column アイコン in デザインエディター ウィンドウ and the オンラインブラウザー.

 

Viewing 一意キー制約s

After you have executed the change script, the 一意キー ic_unique-key-column アイコン is displayed to the left of the 列名 in the Columns folder of the オンラインブラウザー and when you show the table in デザインエディター ウィンドウ. オンラインブラウザー内で、 the name of the 一意キー制約 will also show up in the Keys sub-folder of the 個々の table and will be marked with the 一意キー ic_unique-key-constraint アイコン.

ob_UK-constraint


design_unique-key

オンラインブラウザー内で、 the column definition can be viewed in detail by expanding the 一意キー entry in the Keys folder.


デザインエディター ウィンドウ内で、 the column the 一意キー is assigned to is displayed in bold when you select the 一意キー制約 in the Keys section.

 

Modifying a 一意キー制約

You can rename, delete or change the definition of a 一意キー制約. Note that the 一意キー制約 is always deleted first and then recreated with the new definition. The 個々の SQL statement is generated automatically in the データベース構造変更スクリプト window if you modify the 一意キー definition in デザインエディター ウィンドウ. A 一意キー cannot be deleted if it is referenced by a 外部キー in another table.


(C) 2019 Altova GmbH