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 Indexes4.3 Managing IndexesUse CHECK constraints when you need to enforce integrity rules based on logicalexpressions, such as comparisons. Never use CHECK constraints when any of the othertypes of integrity constraints can provide the necessary checking.Examples of CHECK constraints include the following:■ A CHECK constraint on employee salaries so that no salary value is less than 0.■■A CHECK constraint on department locations so that only the locations Boston,New York, and Dallas are allowed.A CHECK constraint on the salary and commissions columns to prevent thecommission from being larger than the salary.4.2.5.4 Foreign KeyWhenever two tables contain one or more common columns, you can enforce therelationship between the tables through a referential integrity constraint with a foreignkey. A foreign key requires that all column values in the child table exist in the parenttable. The table that includes the foreign key is called the dependent or child table. Thetable that is referenced is called the parent table.An example of a foreign key constraint is when the department column of theemployees table (child) must contain a department ID that exists in the parentdepartments table.Foreign keys can be comprised of multiple columns. Such a composite foreign keymust reference a composite primary or unique key of the exact same structure, withthe same number of columns and the same data types. Because composite primary andunique keys are limited to 32 columns, a composite foreign key is also limited to 32columns. You must use the same data type for corresponding columns in the parentand child tables. The column names do not need to match.Indexes are optional structures associated with tables. You can create them to improvequery performance. Just as the index in this book helps you to quickly locate specificinformation, an <strong>Oracle</strong> Database index provides a quick access path to table data.You can create indexes on one or more columns of a table. After an index is created, itis automatically maintained and used by <strong>Oracle</strong> Database. Changes to a table's data orstructure, such as adding new rows, updating rows, or deleting rows, areautomatically incorporated into all relevant indexes with complete transparency to theuser.Some indexes are created implicitly through constraints that are placed on a table. Forexample, a column with the constraint that its values be unique causes <strong>Oracle</strong>Database to create a unique key index.<strong>Oracle</strong> Database automatically creates the indexes necessary to support data integritydefined with constraints when you add or enable those constraints. For performancepurposes, you might want to add an index to the columns you define in a child tablewhen adding a foreign key constraint. Before you add additional indexes, you shouldexamine the performance of your database. You can then compare performance afterthe new indexes are added.After index creation, <strong>Oracle</strong> Database automatically synchronizes the index with anysubsequent inserts, updates, or deletes to the base table.Indexes are generally of value to queries and to <strong>SQL</strong> statements that need to operateon a single, existing row or a small number of existing rows. Too many indexes can4-6 <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!