How do I index a foreign key in Oracle?
+2
A:
CREATE TABLE reftable (id INT NOT NULL PRIMARY KEY)
CREATE TABLE mytable (id INT NOT NULL, ref INT NOT NULL)
ALTER TABLE mytable
ADD CONSTRAINT fk_mytable_ref_reftable
FOREIGN KEY (ref) REFERENCES reftable (id)
CREATE INDEX ix_mytable_ref ON mytable (ref)
The column in another table (the one you are referencing) must be a PRIMARY KEY
or have a UNIQUE
constraint defined on it, which means it already has an index.
Quassnoi
2009-08-25 12:46:57
got it thanks
Ajay
2009-08-25 12:54:36
A:
You cannot index the foreign key constraint itself, but you can index the columns the foreign key is defined on.
Regards, Rob.
Rob van Wijk
2009-08-25 12:48:19