Skip to Main Content
Oracle SQL*Plus: The Definitive Guide
book

Oracle SQL*Plus: The Definitive Guide

by Jonathan Gennick
March 1999
Intermediate to advanced content levelIntermediate to advanced
528 pages
14h 39m
English
O'Reilly Media, Inc.
Content preview from Oracle SQL*Plus: The Definitive Guide

Table Constraints

Information about constraints can be obtained from two data dictionary views: ALL_CONSTRAINTS and ALL_CONS_COLUMNS. ALL_CONSTRAINTS returns one row for each constraint, and is the only view you need to look at for the definition of a check constraint. Foreign key, primary key, and unique constraints are defined on one or more columns, so for these there is a one-to-many relationship between ALL_CONSTRAINTS and ALL_CONS_COLUMNS. Foreign keys are the most complicated, because to get a complete picture of a foreign key constraint, you need to join the ALL_CONS_COLUMNS table to itself, then refer back to the ALL_CONSTRAINTS view again. The reason for this is that a foreign key may be attached to either a primary key constraint or a unique constraint. It’s important to know which of the columns in the parent table matter.

Different Constraint Types Need Different Queries

There are four different types of constraints that can be created on a table. The four types are:

CHECK
PRIMARY KEY
UNIQUE
FOREIGN KEY

These types are different enough that, with the exception of the PRIMARY KEY and UNIQUE constraints, you need a slightly different query for each in order to see the definition.

CHECK constraints

A check constraint is simply an expression that must be true for each row in a table. This is the simplest of the constraint types when it comes to querying the data dictionary tables. The check expression is stored in the SEARCH_CONDITION column of the ALL_CONSTRAINTS table. ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Oracle SQL*Plus: The Definitive Guide, 2nd Edition

Oracle SQL*Plus: The Definitive Guide, 2nd Edition

Jonathan Gennick
Oracle PL/SQL Programming, Third Edition

Oracle PL/SQL Programming, Third Edition

Steven Feuerstein, Bill Pribyl
Oracle SQL

Oracle SQL

Dan Hotka

Publisher Resources

ISBN: 1565925785Supplemental ContentCatalog PageErrata