Use the following approach to create tables with constraints and indexes:

foreverlee發表於2008-10-23

Use the following approach to create tables with constraints and indexes:

[@more@]

1.

should be created enabled and validated. All other constraints (

Create the tables with the constraints. NOT NULL constraints can be unnamed andCHECK, UNIQUE,

PRIMARY KEY

, and FOREIGN KEY) should be named and created disabled.

See Also:

information about the

Oracle Database SQL Language Reference for moreCREATE INDEX and ALTER INDEX

statements, as well as restrictions on rebuilding indexes

See Also:

Database Administrator's Guide

syntax for this statement

Oracle Database SQL Language Reference and Oraclefor more information about the

Using Function-based Indexes for Performance

Using Indexes and Clusters

2.

15-7Load old data into the tables.

3.

Create all indexes, including indexes needed for constraints.

4.

Enable novalidate all constraints. Do this to primary keys before foreign keys.

5.

Allow users to query and modify data.

6.

constraints. Do this to primary keys before foreign keys. For example,

With a separate ALTER TABLE statement for each constraint, validate all

CREATE TABLE t (a NUMBER CONSTRAINT apk PRIMARY KEY DISABLE,

b NUMBER NOT NULL);

CREATE TABLE x (c NUMBER CONSTRAINT afk REFERENCES t DISABLE);

Now you can use Import or Fast Loader to load data into table

t.

CREATE UNIQUE INDEX tai ON t (a);

CREATE INDEX tci ON x (c);

ALTER TABLE t MODIFY CONSTRAINT apk ENABLE NOVALIDATE;

ALTER TABLE x MODIFY CONSTRAINT afk ENABLE NOVALIDATE;

At this point, users can start performing

on table

INSERTs, UPDATEs, DELETEs, and SELECTst.

ALTER TABLE t ENABLE CONSTRAINT apk;

ALTER TABLE x ENABLE CONSTRAINT afk;

Now the constraints are enabled and validated.

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/76065/viewspace-1012310/,如需轉載,請註明出處,否則將追究法律責任。

相關文章