← Oracle Database SQL: queries and operations
06 / 8 · 45 MIN

Integrity, sequences, and indexes

Distinguish data rules, identifier generation, and access structures.

Concept and mechanism

Constraints express requirements the database must enforce. CHECK rejects FALSE, but an UNKNOWN expression can pass; requiring a known positive amount also needs NOT NULL. UNIQUE on an optional column can accept several NULL rows, whereas a primary key requires presence and uniqueness.

Foreign keys connect references to valid keys and expose mapping errors during loads. Do not disable them merely to obtain a green result. When a constraint fails, identify the violated rule and authorized correction flow.

Changing key representation or adding a commit does not replace referential integrity. Use sample rows that exercise both missing and conflicting references during review.

Guided application

In a fictional platform, a sequence supplies technical keys but can leave gaps after rollback or loss of cached values. NOCACHE does not turn that mechanism into gap-free business numbering. Unsynchronized MAX(id)+1 creates collision risk between sessions.

If the business requires specific sequential control, design it separately with concurrency and audit requirements. Indexes accelerate particular access paths but consume space and write effort; assess queries, selectivity, and observed plans.

A nonunique index enforces neither positive values nor presence. For an updatable view, WITH CHECK OPTION can retain the filter for changes made through it, whereas WITH READ ONLY prevents DML. Confirm the mechanism matching the intended rule.

IN PRACTICE

amount NUMBER NOT NULL CHECK (amount > 0) expresses presence and positivity; a simple index does not replace those rules.

Common pitfalls

CHECK as NOT NULL; UNIQUE as primary key; sequence as continuous ledger; index as cost-free benefit.

Related topics: Model, SELECT, and result population · Functions, conversions, and data contracts · Joins, grain, and aggregation

Take this idea with you

Connect each requirement to the mechanism actually enforcing it.

Create account

References

Oracle® is a registered trademark of Oracle and/or its affiliates. bigsavant.com is an independent preparation platform and is not affiliated with, associated with, sponsored, authorised or endorsed by Oracle. Content and questions are original, are not official exam questions, and completing our tests does not award or guarantee any certification. Names are used only to identify the subject. All other trademarks belong to their respective owners.