2016-05-27 11:13:36 -05:00
|
|
|
.. _unique_constraint_dialog:
|
|
|
|
|
2018-06-15 03:14:12 -05:00
|
|
|
*********************************
|
|
|
|
`Unique Constraint Dialog`:index:
|
|
|
|
*********************************
|
2016-05-27 11:13:36 -05:00
|
|
|
|
2019-03-08 09:29:05 -06:00
|
|
|
Use the *Unique constraint* dialog to define a unique constraint for a specified
|
|
|
|
table. Unique constraints ensure that the data contained in a column, or a group
|
|
|
|
of columns, is unique among all the rows in the table.
|
2016-05-27 11:13:36 -05:00
|
|
|
|
2019-03-08 09:29:05 -06:00
|
|
|
The *Unique constraint* dialog organizes the development of a unique constraint
|
|
|
|
through the following dialog tabs: *General* and *Definition*. The *SQL* tab
|
|
|
|
displays the SQL code generated by dialog selections.
|
2016-05-27 11:13:36 -05:00
|
|
|
|
|
|
|
.. image:: images/unique_constraint_general.png
|
2018-01-11 10:58:30 -06:00
|
|
|
:alt: Unique Constraint dialog general tab
|
2019-03-08 09:29:05 -06:00
|
|
|
:align: center
|
2016-05-27 11:13:36 -05:00
|
|
|
|
|
|
|
Use the fields in the *General* tab to identify the unique constraint:
|
|
|
|
|
2019-03-08 09:29:05 -06:00
|
|
|
* Use the *Name* field to add a descriptive name for the unique constraint.
|
|
|
|
The name will be displayed in the *pgAdmin* tree control.
|
2016-05-27 11:13:36 -05:00
|
|
|
|
|
|
|
Click the *Definition* tab to continue.
|
|
|
|
|
|
|
|
.. image:: images/unique_constraint_definition.png
|
2018-01-11 10:58:30 -06:00
|
|
|
:alt: Unique Constraint dialog definition tab
|
2019-03-08 09:29:05 -06:00
|
|
|
:align: center
|
2016-05-27 11:13:36 -05:00
|
|
|
|
|
|
|
Use the fields in the *Definition* tab to define the unique constraint:
|
|
|
|
|
2019-03-08 09:29:05 -06:00
|
|
|
* Click inside the *Columns* field and select one or more column names from the
|
|
|
|
drop-down listbox. To delete a selection, click the *x* to the left of the
|
|
|
|
column name. The unique constraint should be different from the primary key
|
|
|
|
constraint defined for the same table; the selected column(s) for the
|
|
|
|
constraints must be distinct.
|
|
|
|
* Use *Include columns* field to specify columns for *INCLUDE* clause of the
|
|
|
|
constraint. This option is available in Postgres 11 and later.
|
|
|
|
* Select the name of the tablespace in which the unique constraint will reside
|
|
|
|
from the drop-down listbox in the *Tablespace* field.
|
|
|
|
* Select the name of an index from the drop-down listbox in the *Index* field.
|
|
|
|
This field is optional. Adding a unique constraint will automatically create a
|
|
|
|
unique B-tree index on the column or group of columns listed in the
|
|
|
|
constraint, and will force the column(s) to be marked NOT NULL.
|
|
|
|
* Use the *Fill Factor* field to specify a fill factor for the table and index.
|
|
|
|
The fill factor for a table is a percentage between 10 and 100. 100 (complete
|
|
|
|
packing) is the default.
|
|
|
|
* Move the *Deferrable?* switch to the *Yes* position to specify the timing of
|
|
|
|
the constraint is deferrable and can be postponed until the end of the
|
|
|
|
statement. The default is *No*.
|
|
|
|
* If enabled, move the *Deferred?* switch to the *Yes* position to specify the
|
|
|
|
timing of the constraint is deferred to the end of the statement. The default
|
|
|
|
is *No*.
|
2016-05-27 11:13:36 -05:00
|
|
|
|
|
|
|
Click the *SQL* tab to continue.
|
|
|
|
|
2019-03-08 09:29:05 -06:00
|
|
|
Your entries in the *Unique constraint* dialog generate a SQL command (see an
|
|
|
|
example below). Use the *SQL* tab for review; revisit or switch tabs to make any
|
|
|
|
changes to the SQL command.
|
2016-05-27 11:13:36 -05:00
|
|
|
|
2019-03-08 09:29:05 -06:00
|
|
|
Example
|
|
|
|
*******
|
2016-05-27 11:13:36 -05:00
|
|
|
|
2019-03-08 09:29:05 -06:00
|
|
|
The following is an example of the sql command generated by user selections in
|
|
|
|
the *Unique constraint* dialog:
|
2016-05-27 11:13:36 -05:00
|
|
|
|
|
|
|
.. image:: images/unique_constraint_sql.png
|
2018-01-11 10:58:30 -06:00
|
|
|
:alt: Unique Constraint dialog sql tab
|
2019-03-08 09:29:05 -06:00
|
|
|
:align: center
|
2016-05-27 11:13:36 -05:00
|
|
|
|
2019-03-08 09:29:05 -06:00
|
|
|
The example shown demonstrates creating a unique constraint named *name_con* on
|
|
|
|
the *name* column of the *distributors* table.
|
2016-05-27 11:13:36 -05:00
|
|
|
|
2018-01-11 10:58:30 -06:00
|
|
|
|
2019-03-08 09:29:05 -06:00
|
|
|
* Click the *Info* button (i) to access online help.
|
2016-05-27 11:13:36 -05:00
|
|
|
* Click the *Save* button to save work.
|
|
|
|
* Click the *Cancel* button to exit without saving work.
|
2016-06-21 03:06:44 -05:00
|
|
|
* Click the *Reset* button to restore configuration parameters.
|