23.10.2012 Views

Openedge Data Management: SQL Reference - Product ...

Openedge Data Management: SQL Reference - Product ...

Openedge Data Management: SQL Reference - Product ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Table constraints<br />

Syntax<br />

<strong>SQL</strong> Compliance<br />

Progress Software Corporation specific extension.<br />

Related statements<br />

ALTER TABLE, CREATE INDEX, CREATE TABLE<br />

Table constraints<br />

Specifies a constraint for a table that restricts the values that the table can store. INSERT, UPDATE,<br />

or DELETE statements that violate the constraint fail. <strong>SQL</strong> returns a constraint violation error.<br />

Table constraints have syntax and behavior similar to column constraints. Note the following<br />

differences:<br />

• The definitions of the table constraints are separated from the column definitions by<br />

commas.<br />

• Table constraint definitions can include more than one column, and <strong>SQL</strong> evaluates the<br />

constraint based on the combination of values stored in all the columns.<br />

CONSTRAINT constraint_name<br />

PRIMARY KEY ( column [ , ... ] )<br />

| UNIQUE ( column [ , ... ] )<br />

| FOREIGN KEY ( column [, ... ] )<br />

REFERENCES [ owner_name.]table_name [ ( column [ , ... ] ) ]<br />

| CHECK ( search_condition )<br />

CONSTRAINT constraint_name<br />

Allows you to assign a name that you choose to the table constraint. While this<br />

specification is optional, this facilitates making changes to the table definition, since the<br />

name you specify is in your source CREATE TABLE statement. If you do not specify a<br />

constraint_name, the database assigns a name. These names can be long and unwieldy,<br />

and you must query system tables to determine the name.<br />

PRIMARY KEY ( column [ , ... ] )<br />

Defines the column list as the primary key for the table. There can be at most one primary<br />

key for a table.<br />

All the columns that make up a table level primary key must be defined as NOT NULL, or the<br />

CREATE TABLE statement fails. The combination of values in the columns that make up the<br />

primary key must be unique for each row in the table.<br />

Other tables can name primary keys in their REFERENCES clauses. If they do, <strong>SQL</strong> restricts<br />

operations on the table containing the primary key in the following ways:<br />

• DROP TABLE statements that delete the table fail<br />

65

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!