12.07.2015 Views

Oracle SQL Developer

Oracle SQL Developer

Oracle SQL Developer

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Managing Tables4.2.4 Column ConstraintsYou can enforce rules by defining integrity constraints more reliably than by addinglogic to your application. <strong>Oracle</strong> Database can check that all the data in a table obeysan integrity constraint faster than an application can.Some constraints can be defined at the column level or at the table level. Column levelconstraints are syntactically defined where the column to which the constraint appliesis defined. Table level constraints are syntactically defined at the end of the tabledefinition.Column constraints are optional elements that determine what values are valid in thecolumn.The NOT NULL constraint on a column requires that the column must contain a valuewhenever a row is inserted or updated. Unlike other constraints described in"Table-Level Constraints" on page 4-4, which may be defined as part of the columndefinition or part of the table definition, the NOT NULL constraint must be defined aspart of the column definition.Use a NOT NULL constraint when the data is required for the integrity of the database.For example, if all employees must belong to a specific department, then the columnthat contains the department identifier should be defined with a NOT NULL constraint.On the other hand, do not define a column as NOT NULL if the data may be unknownor may not exist when rows are added or changed, for example, the second, optionalline in a mailing address.A primary key constraint automatically adds a NOT NULL constraint to the column orcolumns included in the primary key, in addition to enforcing uniqueness among thevalues.4.2.5 Table-Level ConstraintsYou can apply rules to preserve the integrity of your data. For example, in a tablecontaining employee data, the employee email column must be unique. Similarly, inthis table you cannot have two employees with the same employee Id.<strong>Oracle</strong> Database enables you to apply data integrity rules as constraints on columns atthe table level. Any attempt to insert, update, or remove a row that violates aconstraint results in an error and the statement is rolled back. Likewise, any attempt toapply a new constraint to a populated table also results in an error if any existing rowviolates the new constraint.The types of constraints you can apply at the table level are as follows:■ Primary Key■ Unique Key■ Check Constraint■ Foreign KeyConstraints can be created and, in most cases, modified with a number of differentstatus values. The options include enabled or disabled, which determine if theconstraint is checked when rows are added, modified, or removed; and deferred orimmediate, which cause constraint validation to occur at the end of a transaction or atthe end of a statement, respectively.See Also: <strong>Oracle</strong> Database Concepts for more information onconstraints.4-4 <strong>SQL</strong> <strong>Developer</strong> Online Help

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

Saved successfully!

Ooh no, something went wrong!